Skip to content

Commit

Permalink
chore: fix IMPORT not allowed in master
Browse files Browse the repository at this point in the history
  • Loading branch information
Lufftre committed Jan 10, 2025
1 parent 7637bea commit ed683b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 1 addition & 2 deletions m3u8/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st
defineType = QUERYPARAM
_, err = fmt.Sscanf(line, "#EXT-X-DEFINE:QUERYPARAM=%q", &name)
case strings.HasPrefix(line, "#EXT-X-DEFINE:IMPORT="):
defineType = IMPORT
_, err = fmt.Sscanf(line, "#EXT-X-DEFINE:IMPORT=%q", &name)
return fmt.Errorf("EXT-X-DEFINE IMPORT not allowed in master playlist")
default:
return fmt.Errorf("unknown EXT-X-DEFINE format: %s", line)
}
Expand Down
11 changes: 10 additions & 1 deletion m3u8/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,16 @@ func TestDecodeMasterPlaylistWithDefines(t *testing.T) {
is.Equal(p.Defines[1].Type, QUERYPARAM)
is.Equal(p.Defines[1].Value, "")
}

func TestDecodeMasterPlaylistWithInvalidDefines(t *testing.T) {
is := is.New(t)
f, err := os.Open("sample-playlists/master-with-defines-invalid.m3u8")
is.NoErr(err) // must open file
p := NewMasterPlaylist()
err = p.DecodeFrom(bufio.NewReader(f), false)
is.NoErr(err) // must decode playlist
// check parsed values
is.Equal(len(p.Defines), 0) // must be 0 defines
}
func TestDecodeMediaPlaylistWithDefines(t *testing.T) {
is := is.New(t)
f, err := os.Open("sample-playlists/media-playlist-with-defines.m3u8")
Expand Down
13 changes: 13 additions & 0 deletions m3u8/sample-playlists/master-with-defines-invalid.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#EXTM3U
#EXT-X-VERSION:6
#EXT-X-DEFINE:IMPORT="Define1"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=300000
chunklist-b300000.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=600000
chunklist-b600000.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=850000
chunklist-b850000.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000
chunklist-b1000000.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1500000
chunklist-b1500000.m3u8

0 comments on commit ed683b6

Please sign in to comment.