Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Handle irregular white-space in segment URIs #6396

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/loader/m3u8-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const IS_MEDIA_PLAYLIST = /^#EXT(?:INF|-X-TARGETDURATION):/m; // Handle empty Me
const LEVEL_PLAYLIST_REGEX_FAST = new RegExp(
[
/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source, // duration (#EXTINF:<duration>,<title>), group 1 => duration, group 2 => title
/(?!#) *(\S[\S ]*)/.source, // segment URI, group 3 => the URI (note newline is not eaten)
/(?!#) *(\S[^\r\n]*)/.source, // segment URI, group 3 => the URI (note newline is not eaten)
/#EXT-X-BYTERANGE:*(.+)/.source, // next segment's byterange, group 4 => range spec (x@y)
/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source, // next segment's program date/time group 5 => the datetime spec
/#.*/.source, // All other non-segment oriented tags will match with all groups empty
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/loader/playlist-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,30 @@ http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/video/107/
expect(result.fragments[1].relurl).to.equal('1');
});

it('parse level with unicode white-space in fragment URI', function () {
const uriWithIrregularWs0 = 'sample-mp4-file\u3000_240p_00000.ts';
const uriWithIrregularWs1 = 'sample-mp4-file\u3000_another\u3000_00001.ts';
const level = `#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:2
#EXTINF:2,
${uriWithIrregularWs0}
#EXTINF:2,
${uriWithIrregularWs1}
#EXT-X-ENDLIST`;
const result = M3U8Parser.parseLevelPlaylist(
level,
'http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/frag(5)/video/107/282/158282701_mp4_h264_aac_hq.m3u8#cell=core',
0,
PlaylistLevelType.MAIN,
0,
null,
);
expect(result.fragments).to.have.lengthOf(2);
expect(result.fragments[0].relurl).to.equal(uriWithIrregularWs0);
expect(result.fragments[1].relurl).to.equal(uriWithIrregularWs1);
});

it('parse level with EXTINF line without comma', function () {
const level = `#EXTM3U
#EXT-X-VERSION:3
Expand Down
Loading