commit 9998245d9a03cb458c2c2b45f064420aada04775
parent 92dc63362577948c330a0ab6614164fb1f056eb4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 12:55:33 -0500
vtt tests: the old cue line's leniencies are pinned
What the hh:mm:ss.mmm reading accepted before short-form support it still
accepts, to the same numbers: a match anywhere in the line, minutes and seconds
out of range, extra millisecond digits on the end stamp, any whitespace around
the arrow, finite times throughout; and a document with hh:mm:ss.mmm cue lines
is not reclassified by short-form word tags. Each passes on the parser at
fc5f479e and fails on the contributed one.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
1 file changed, 70 insertions(+), 0 deletions(-)
diff --git a/common/lib/vtt.test.ts b/common/lib/vtt.test.ts
@@ -125,3 +125,73 @@ test("point cues preserve original text and timestamps", () => {
assert.deepEqual(parseVtt("WEBVTT\n\n00:01.000 --> 00:01.000\nPoint\n"),
[{ start: 1, end: 1, text: "Point" }]);
});
+
+// THE OLD CUE LINE STAYS LENIENT. Short-form support is a second reading, tried
+// only on a line the hh:mm:ss.mmm one does not match; every published site's
+// cues came through the lenient one, so what it accepted it still accepts, to
+// the same numbers. Each test below is a tightening the contributed parser
+// made; each passes on the parser as it was before short-form support.
+test("a hh:mm:ss.mmm cue line is found anywhere in its line, as before", () => {
+ const cue = (line: string) => parseVtt(`WEBVTT\n\n${line}\nText\n`);
+ const want = [{ start: 1, end: 2, text: "Text" }];
+ assert.deepEqual(cue("x00:00:01.000 --> 00:00:02.000"), want);
+ assert.deepEqual(cue("-00:00:01.000 --> 00:00:02.000"), want);
+ assert.deepEqual(cue("cue-7 00:00:01.000 --> 00:00:02.000"), want);
+ assert.deepEqual(cue("00:00:01.000 --> 00:00:02.000align:start"), want);
+ // More than two hour digits at the START: the last two are read.
+ assert.deepEqual(cue("100:00:01.000 --> 00:00:02.000"), want);
+});
+
+test("a hh:mm:ss.mmm cue line's minutes and seconds are not range-checked, as before", () => {
+ assert.deepEqual(parseVtt("WEBVTT\n\n00:75:90.000 --> 01:99:60.500\nOut of range\n"), [
+ { start: 75 * 60 + 90, end: 3600 + 99 * 60 + 60.5, text: "Out of range" },
+ ]);
+});
+
+test("a hh:mm:ss.mmm end stamp with extra millisecond digits reads its first three, as before", () => {
+ assert.deepEqual(parseVtt("WEBVTT\n\n00:00:01.000 --> 00:00:02.5009\nLong fraction\n"), [
+ { start: 1, end: 2.5, text: "Long fraction" },
+ ]);
+});
+
+test("a hh:mm:ss.mmm cue line takes any whitespace around the arrow, as before", () => {
+ assert.deepEqual(parseVtt("WEBVTT\n\n00:00:01.000 --> \t00:00:02.000\nSpaced\n"), [
+ { start: 1, end: 2, text: "Spaced" },
+ ]);
+});
+
+// The contributed parser returned NaN for a stamp it could not read where the
+// old one returned 0. Neither is reachable through a matched hh:mm:ss.mmm line;
+// what is pinned is that every lenient line above yields finite numbers.
+test("no cue the old line accepts carries a NaN time", () => {
+ const src = "WEBVTT\n\nx00:00:01.000 --> 00:00:02.0009\nA\n\n00:75:90.000 --> 00:99:99.000\nB\n";
+ const cues = parseVtt(src);
+ assert.equal(cues.length, 2);
+ for (const c of cues) assert.ok(Number.isFinite(c.start) && Number.isFinite(c.end));
+});
+
+// A document the old parser read cues from keeps its SHAPE: short-form word
+// tags make a document rolling only when it has no hh:mm:ss.mmm cue line.
+test("short-form word tags do not reclassify a document with hh:mm:ss.mmm cue lines", () => {
+ const src = "WEBVTT\n\n00:00:01.000 --> 00:00:02.000\n<00:01.000><c>Hello</c> <00:01.500><c>world</c>\n\n"
+ + "00:00:02.000 --> 00:00:02.010\nHello again\n";
+ assert.equal(hasWordTiming(src), false);
+ assert.deepEqual(parseVtt(src), [
+ { start: 1, end: 2, text: "Hello world" },
+ { start: 2, end: 2.01, text: "Hello again" },
+ ]);
+});
+
+test("a short-form tag inside a hh:mm:ss.mmm rolling line stays text, as before", () => {
+ const src = "WEBVTT\n\n00:00:01.000 --> 00:00:02.000\none<00:00:01.500><c> two</c><00:01.800>\n";
+ assert.deepEqual(parseVtt(src), [{ start: 1, end: 2, text: "one two<00:01.800>" }]);
+});
+
+test("a short-form cue line in a body is that cue's text, and one on its own is a cue", () => {
+ const src = "WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nFirst\n00:03.000 --> 00:04.000\n\n"
+ + "00:05.000 --> 00:06.000\nSecond\n";
+ assert.deepEqual(parseVtt(src), [
+ { start: 1, end: 2, text: "First 00:03.000 --> 00:04.000" },
+ { start: 5, end: 6, text: "Second" },
+ ]);
+});