From 5e6cfba21941c3da002130178ebcce09f9ee5cc8 Mon Sep 17 00:00:00 2001 From: tommy Date: Wed, 17 Sep 2025 14:39:24 -0400 Subject: [PATCH] Add style validation for timestamps --- lib/parser.js | 9 ++++++++- test/parser.test.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/parser.js b/lib/parser.js index 4b06a19..007f42a 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -167,9 +167,16 @@ function parseCue (cue, i, strict) { ); } - // TODO better style validation styles = times[1].replace(TIMESTAMP_REGEXP, '').trim(); + if (styles !== '') { + styles.split(' ').forEach((style) => { + if (!style.includes(':')) { + throw new ParserError(`Invalid inline style (cue #${i})`); + } + }); + } + lines.shift(); text = lines.join('\n'); diff --git a/test/parser.test.js b/test/parser.test.js index ddaa33e..c7f34e0 100644 --- a/test/parser.test.js +++ b/test/parser.test.js @@ -478,4 +478,14 @@ a`; .should.throw(parserError, /Invalid cue timestamp/); } ); + + it('should throw an error if the inline style is invalid', () => { + const input = `WEBVTT + +1 +00:00.000 --> 00:00.001 0`; + + (() => { parse(input); }) + .should.throw(parserError, /Invalid inline style/); + }); });