Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(text-track): normalize whitespace in content before parsing#1716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pzanella wants to merge1 commit intovidstack:main
base:main
Choose a base branch
Loading
frompzanella:fix/text-track

Conversation

@pzanella
Copy link

@pzanellapzanella commentedOct 29, 2025
edited
Loading

Related:

Fixes SRT subtitle parsing issues where comma-separated milliseconds (e.g.,00:00:01,000) fail to parse when content contains indented template literals.
Closes#1671

Description:

This PR adds whitespace normalization to the#parseContent method inTextTrack to handle indented template literal content before passing it to themedia-captions parser.

Changes:

  • Core Fix: Addedcontent.split('\n').map(line => line.trim()).join('\n').trim() to normalize whitespace while preserving line structure
  • Test Coverage: Added comprehensive unit tests (16 test cases) covering whitespace normalization scenarios
  • Edge Cases: Handles mixed indentation, Windows line endings, tabs, and extremely large indentation
  • Backward Compatibility: Preserves empty lines between subtitle blocks and doesn't affect JSON content parsing

Problem Solved:
Themedia-captions library expects clean content without leading/trailing whitespace. When using template literals with indentation for inline SRT content, the parser would fail with errors like"cue start timestamp \'00:00:00,000\' is invalid" even though the SRT format itself was correct.

Ready?

Yes - All tests passing, edge cases covered, and backward compatibility maintained.

Anything Else?

Before (Failed):

consttrack=newTextTrack({kind:'subtitles',type:'srt',content:`    1    00:00:01,000 --> 00:00:05,000    First subtitle`});// ❌ Error: cue start timestamp `00:00:01,000` is invalid

After (Works)

consttrack=newTextTrack({kind:'subtitles',type:'srt',content:`    1    00:00:01,000 --> 00:00:05,000    First subtitle`});// ✅ Parses successfully - whitespace normalized automatically

Test Results:16/16 tests passing

Test CategoryTestsStatusCoverage
Whitespace Normalization11✅ PassTemplate literals, mixed indentation, leading/trailing whitespace
Edge Cases3✅ PassTabs, Windows line endings (\r\n), extreme indentation
Regression Tests2✅ PassSRT comma timestamps, VTT period timestamps

Detailed Coverage:

  • ✅ Template literal indentation scenarios
  • ✅ Mixed whitespace handling
  • ✅ Empty line preservation between subtitle blocks
  • ✅ JSON content bypass (no normalization applied)
  • ✅ Windows line endings (\r\n) compatibility
  • ✅ Tab characters and extreme indentation handling
  • ✅ SRT comma timestamps (00:00:01,000) parsing
  • ✅ VTT period timestamps (00:00:01.000) parsing
  • ✅ Complex content with HTML formatting and special characters
  • ✅ Single line content normalization
  • ✅ Whitespace-only content handling

Manual Test Scenarios:

Template Literal Testing

// Test 1: Basic indented SRT contentconsttrack1=newTextTrack({kind:'subtitles',type:'srt',content:`    1    00:00:01,000 --> 00:00:05,000    First subtitle    2    00:00:06,000 --> 00:00:10,000    Second subtitle`});// Expected: ✅ Parses successfully

Cross-platform Line Endings

// Test 2: Windows line endings (\r\n)constwindowsContent="1\r\n00:00:01,000 --> 00:00:05,000\r\nSubtitle text";consttrack2=newTextTrack({kind:'subtitles',type:'srt',content:`${windowsContent}`});// Expected: ✅ Handles \r\n correctly

JSON Content Bypass

// Test 3: JSON content should skip normalizationconsttrack3=newTextTrack({kind:'subtitles',type:'json',content:{cues:[{startTime:1,endTime:5,text:"Test"}]}});// Expected: ✅ No normalization applied to JSON

VTT Format Testing

// Test 4: VTT with period timestampsconsttrack4=newTextTrack({kind:'subtitles',type:'vtt',content:`    WEBVTT    1    00:00:01.000 --> 00:00:05.000    VTT subtitle`});// Expected: ✅ VTT format works with periods

Edge Case Validation

// Test 5: Mixed whitespace (tabs + spaces)constmixedContent="\t  1\n\t00:00:01,000 --> 00:00:05,000\n\t  Mixed whitespace";consttrack5=newTextTrack({kind:'subtitles',type:'srt',content:mixedContent});// Expected: ✅ Handles mixed tab/space indentation

@pzanellapzanella mentioned this pull requestOct 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Support srt file format

1 participant

@pzanella

[8]ページ先頭

©2009-2025 Movatter.jp