Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split metadata strings on first colon only #38

Merged
merged 3 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
goatandsheep marked this conversation as resolved.
Show resolved Hide resolved

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