Skip to content

Commit 8d1f00c

Browse files
authoredAug 6, 2020
Merge pull request #38 from jaimefps/fix/parseMeta-unstable-split
Split metadata strings on first colon only
2 parents c70c1e3 + 8b528fc commit 8d1f00c

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed
 

‎lib/parser.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ function parse (input, options) {
7474
function parseMeta (headerParts) {
7575
const meta = {};
7676
headerParts.slice(1).forEach(header => {
77-
const [key, value] = header.split(':').map(t => t.trim());
77+
const splitIdx = header.indexOf(':');
78+
const key = header.slice(0, splitIdx).trim();
79+
const value = header.slice(splitIdx + 1).trim();
7880
meta[key] = value;
7981
});
8082
return Object.keys(meta).length > 0 ? meta : null;

‎package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-webvtt",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "WebVTT parser, compiler, and segmenter with HLS support",
55
"main": "index.js",
66
"scripts": {

‎test/compiler.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ Hello world
454454
const input = {
455455
meta: {
456456
Kind: 'captions',
457-
Language: 'en'
457+
Language: 'en',
458+
'X-TIMESTAMP-MAP=LOCAL': '00:00:00.000,MPEGTS:0'
458459
},
459460
cues: [{
460461
end: 140,
@@ -469,6 +470,7 @@ Hello world
469470
const output = `WEBVTT
470471
Kind: captions
471472
Language: en
473+
X-TIMESTAMP-MAP=LOCAL: 00:00:00.000,MPEGTS:0
472474
473475
1
474476
00:02:15.001 --> 00:02:20.000

‎test/parser.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,19 @@ Language: en
299299
const input = `WEBVTT
300300
Kind: captions
301301
Language: en
302+
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0
302303
303304
1
304305
00:00.000 --> 00:00.001`;
305306
const options = { meta: true };
306307

307308
parse(input, options).should.have.property('valid').be.true;
308309
parse(input, options).should.have.property('meta').be.deep.equal(
309-
{ Kind: 'captions', Language: 'en' }
310+
{
311+
Kind: 'captions',
312+
Language: 'en',
313+
'X-TIMESTAMP-MAP=LOCAL': '00:00:00.000,MPEGTS:0'
314+
}
310315
);
311316
});
312317

0 commit comments

Comments
 (0)
Please sign in to comment.