caption: never derive negative word durations; repair inverted cues#272
Open
maboa wants to merge 1 commit into
Open
caption: never derive negative word durations; repair inverted cues#272maboa wants to merge 1 commit into
maboa wants to merge 1 commit into
Conversation
When a word has no data-d, its duration is derived from the next span's data-m with only a positive cap — if the next data-m sits at or before this word's (duplicate stamps on split tokens, out-of-order times after edits) the duration went negative, yielding a cue with stop < start. Browsers drop such cues from a VTT track, several SRT consumers reject the whole file, and a negative arithmetic result wrapped to a ~24h timestamp via the Date-based formatSeconds. Two-part fix: - clamp the derived duration at zero - applyTimingSafeguards now REPAIRS inverted/zero-length cues instead of stepping over them: stop is treated as the start and the cue is extended to the minimum readable duration (capped at the next cue's start; never emitting stop <= start even against out-of-order cue starts) Reported in hyperaudio/hyperaudio-lite-editor#411 from a review of the vendored copy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a word span has no
data-d,caption.jsderives its duration from the next span'sdata-mwith only a positive cap (js/caption.js:132). If the nextdata-msits at or before this word's start — duplicate timestamps on split/glued tokens, or out-of-order times after manual edits — the duration goes negative, producing a cue withstop < start.Downstream,
applyTimingSafeguardsdeliberately skips exactly these (stop <= start), so the inverted cue serializes: browsers silently drop it from the VTT track, several SRT consumers reject the whole file, and a below-zero result wraps to a~23:59:59timestamp via theDate-basedformatSeconds.Fix
0so a word never ends before it starts.applyTimingSafeguardsnow repairs inverted/zero-length cues instead of stepping over them:stopis treated asstart, then the cue is extended to the minimum readable duration (capped at the next cue's start, never emittingstop <= starteven against out-of-order cue starts).Tests
Two regression tests in
__TEST__/caption.test.js— a missingdata-dbeside a non-increasingdata-m(no negative / 24h timestamp), and an explicit zero-duration word (cue repaired, not dropped). Full suite green (73 passing).Note
Found by reviewing the vendored copy in hyperaudio/hyperaudio-lite-editor#411 — a hardening fix against malformed/edited timing rather than an observed failure, but such input produces genuinely broken VTT/SRT output today.