Skip to content

Commit

Permalink
Merge pull request #38 from jaimefps/fix/parseMeta-unstable-split
Browse files Browse the repository at this point in the history
Split metadata strings on first colon only
  • Loading branch information
goatandsheep authored Aug 6, 2020
2 parents c70c1e3 + 8b528fc commit 8d1f00c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function parse (input, options) {
function parseMeta (headerParts) {
const meta = {};
headerParts.slice(1).forEach(header => {
const [key, value] = header.split(':').map(t => t.trim());
const splitIdx = header.indexOf(':');
const key = header.slice(0, splitIdx).trim();
const value = header.slice(splitIdx + 1).trim();
meta[key] = value;
});
return Object.keys(meta).length > 0 ? meta : null;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-webvtt",
"version": "1.9.0",
"version": "1.9.1",
"description": "WebVTT parser, compiler, and segmenter with HLS support",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion test/compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ Hello world
const input = {
meta: {
Kind: 'captions',
Language: 'en'
Language: 'en',
'X-TIMESTAMP-MAP=LOCAL': '00:00:00.000,MPEGTS:0'
},
cues: [{
end: 140,
Expand All @@ -469,6 +470,7 @@ Hello world
const output = `WEBVTT
Kind: captions
Language: en
X-TIMESTAMP-MAP=LOCAL: 00:00:00.000,MPEGTS:0
1
00:02:15.001 --> 00:02:20.000
Expand Down
7 changes: 6 additions & 1 deletion test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,19 @@ Language: en
const input = `WEBVTT
Kind: captions
Language: en
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0
1
00:00.000 --> 00:00.001`;
const options = { meta: true };

parse(input, options).should.have.property('valid').be.true;
parse(input, options).should.have.property('meta').be.deep.equal(
{ Kind: 'captions', Language: 'en' }
{
Kind: 'captions',
Language: 'en',
'X-TIMESTAMP-MAP=LOCAL': '00:00:00.000,MPEGTS:0'
}
);
});

Expand Down

0 comments on commit 8d1f00c

Please sign in to comment.