Skip to content

fix(webvtt): accept a leading byte-order mark - #293

Merged
dmtrKovalenko merged 2 commits into
dmtrKovalenko:mainfrom
fuadsn:fix/webvtt-leading-bom-280
Dec 4, 2026
Merged

dmtrKovalenko merged 2 commits into
dmtrKovalenko:mainfrom
fuadsn:fix/webvtt-leading-bom-280

Conversation

@fuadsn

@fuadsn fuadsn commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

WebVTT files with a leading UTF-8 byte-order mark were rejected at the signature. Accept one leading mark while keeping error offsets relative to the original file. A malformed signature still fails.

Refs #280 (BOM case only).

The new regression failed on the previous parser. cargo test --locked -p webvtt-parser now passes all 10 unit tests and the doc test. cargo fmt -p webvtt-parser -- --check also passed.

AI assistance: Codex.

Summary by CodeRabbit

  • Bug Fixes
    • Valid WebVTT documents with a leading UTF-8 BOM now parse correctly. Repeated BOMs and BOM-prefixed input without a valid WEBVTT marker return errors, with error offsets accounting for the BOM. For parse errors after a BOM, the reported line and fragment remain consistent with the input, while the byte offset reflects the BOM’s length.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The parser now accepts one leading UTF-8 BOM before the WEBVTT marker. Tests cover parsed cues, rejection of repeated BOMs and invalid headers, and error offsets for BOM-prefixed invalid documents.

Changes: Leading BOM parsing

Layer / File(s) Summary
BOM handling and validation
webvtt-parser/src/vtt_parser.rs, webvtt-parser/src/lib.rs
parse consumes an optional leading BOM before checking for the WEBVTT marker. Tests cover accepted and rejected inputs, and verify that the BOM increases the error offset without changing the line or fragment.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related issues

Suggested reviewers: kremnyi

Merge Risk: Minimal · up to 6ba68

This change lets WebVTT files that start with a single byte-order mark parse correctly. Malformed signatures still fail, and error offsets still point into the original file. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(webvtt): accept a leading byte-order mark" matches the main change. The PR makes the WebVTT parser accept one optional UTF-8 BOM before the WEBVTT signature, and adds tests for that cas…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(webvtt): accept a leading byte-order mark" matches the main change. The PR makes the WebVTT parser accept one optional UTF-8 BOM before the WEBVTT signature, and adds tests for that case, for doubled BOMs, and for error offsets after a BOM. The title is specific, concise, and follows a conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 280778c4-4e6a-41b4-9db8-e998fbb9acbc
Commits

Reviewing files that changed from the base of the PR and between b8f286e and 6ba68f7.

Files selected for processing: 2

  • webvtt-parser/src/lib.rs
  • webvtt-parser/src/vtt_parser.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

dmtrKovalenko
dmtrKovalenko previously approved these changes Dec 3, 2026
@dmtrKovalenko
dmtrKovalenko merged commit 779928a into dmtrKovalenko:main Dec 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants