Skip to content

Commit

Permalink
Bugfix: Handle irregular white-space in segment URIs (#6396)
Browse files Browse the repository at this point in the history
* Update parser pattern to not terminate segment URLs on unicode white-space
Fixes #6381

* Add test for irregular white-space in segment URIs
  • Loading branch information
robwalch committed May 4, 2024
1 parent 805e555 commit 542e75f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/loader/m3u8-parser.ts
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
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

0 comments on commit 542e75f

Please sign in to comment.