Skip to content

Commit f541fec

Browse files
committed
Add style validation for timestamps
1 parent 8dae70d commit f541fec

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/parser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,16 @@ function parseCue (cue, i, strict) {
167167
);
168168
}
169169

170-
// TODO better style validation
171170
styles = times[1].replace(TIMESTAMP_REGEXP, '').trim();
172171

172+
if (styles !== '') {
173+
styles.split(' ').forEach((style) => {
174+
if (!style.includes(':')) {
175+
throw new ParserError(`Invalid inline style (cue #${i})`);
176+
}
177+
});
178+
}
179+
173180
lines.shift();
174181

175182
text = lines.join('\n');

test/parser.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,13 @@ a`;
478478
.should.throw(parserError, /Invalid cue timestamp/);
479479
}
480480
);
481+
482+
it('should throw an error if the inline style is invalid', () => {
483+
const input = `WEBVTT
484+
1
485+
00:00.000 --> 00:00.001 0`;
486+
487+
(() => { parse(input); })
488+
.should.throw(parserError, /Invalid inline style/);
489+
});
481490
});

0 commit comments

Comments
 (0)