mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-06 19:21:31 -07:00
test(subtitles): verify \t nesting cap and document dedup sort order
- Assert collectAssOverrideCommands stops at the recursion cap (exact command count) instead of asserting only the outer tag, using a realistic nesting depth instead of 200k - Document mergeDuplicateCues' precondition that cues are pre-sorted by startTime/endTime/order, since burst detection silently breaks on unsorted input
This commit is contained in:
@@ -127,15 +127,17 @@ test('collectAssOverrideCommands marks tags animated by a wrapping \\t', () => {
|
|||||||
assert.equal(hasAssTemporalOverride(commands), true);
|
assert.equal(hasAssTemporalOverride(commands), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('collectAssOverrideCommands survives pathologically nested \\t tags', () => {
|
test('collectAssOverrideCommands stops descending into deeply nested \\t tags', () => {
|
||||||
const depth = 200000;
|
// Nested far past the recursion cap. Uncapped, this recurses once per level, and a
|
||||||
const block = `{${'\\t(0,500,'.repeat(depth)}\\frz30${')'.repeat(depth)}}文字`;
|
// pathological line (real files reach one or two levels) overflows the stack.
|
||||||
|
const nesting = 32;
|
||||||
|
const block = `{${'\\t(0,500,'.repeat(nesting)}\\frz30${')'.repeat(nesting)}}文字`;
|
||||||
|
|
||||||
const commands = collectAssOverrideCommands(block);
|
const commands = collectAssOverrideCommands(block);
|
||||||
|
|
||||||
// Recursion stops at the nesting cap; the outer tags are still reported, and nothing
|
// The outer `\t` plus one per allowed recursion level, and nothing from below the cap.
|
||||||
// blows the call stack.
|
assert.equal(commands.length, 9);
|
||||||
assert.equal(commands[0]!.name, 't');
|
assert.deepEqual(new Set(commands.map((command) => command.name)), new Set(['t']));
|
||||||
assert.equal(hasAssTemporalOverride(commands), true);
|
assert.equal(hasAssTemporalOverride(commands), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -177,6 +177,12 @@ function collapseAnimationBursts(
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collapse redundant cues. Input must already be sorted by non-decreasing `startTime`,
|
||||||
|
* ties broken by `endTime` then source `order` -- burst detection chains events by
|
||||||
|
* comparing each one against the running end of the events before it, so an unsorted
|
||||||
|
* list breaks runs apart and leaves the frames behind.
|
||||||
|
*/
|
||||||
export function mergeDuplicateCues(
|
export function mergeDuplicateCues(
|
||||||
cues: AnnotatedSubtitleCue[],
|
cues: AnnotatedSubtitleCue[],
|
||||||
format: SubtitleSourceFormat,
|
format: SubtitleSourceFormat,
|
||||||
|
|||||||
Reference in New Issue
Block a user