Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Ignore blank lines in playlist -- fixes panic w/EXT-X-MAP. #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l
}

switch {
case len(line) == 0:
// blank lines are ignored
case !state.tagInf && strings.HasPrefix(line, "#EXTINF:"):
state.tagInf = true
state.listType = MEDIA
Expand Down
17 changes: 9 additions & 8 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func TestDecodeMediaPlaylistExtInfNonStrict2(t *testing.T) {
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
%s
/s.ts
`

tests := []struct {
Expand All @@ -353,18 +354,18 @@ func TestDecodeMediaPlaylistExtInfNonStrict2(t *testing.T) {
wantSegment *MediaSegment
}{
// strict mode on
{true, "#EXTINF:10.000,", false, &MediaSegment{Duration: 10.0, Title: ""}},
{true, "#EXTINF:10.000,Title", false, &MediaSegment{Duration: 10.0, Title: "Title"}},
{true, "#EXTINF:10.000,Title,Track", false, &MediaSegment{Duration: 10.0, Title: "Title,Track"}},
{true, "#EXTINF:10.000,", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: ""}},
{true, "#EXTINF:10.000,Title", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: "Title"}},
{true, "#EXTINF:10.000,Title,Track", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: "Title,Track"}},
{true, "#EXTINF:invalid,", true, nil},
{true, "#EXTINF:10.000", true, nil},

// strict mode off
{false, "#EXTINF:10.000,", false, &MediaSegment{Duration: 10.0, Title: ""}},
{false, "#EXTINF:10.000,Title", false, &MediaSegment{Duration: 10.0, Title: "Title"}},
{false, "#EXTINF:10.000,Title,Track", false, &MediaSegment{Duration: 10.0, Title: "Title,Track"}},
{false, "#EXTINF:invalid,", false, &MediaSegment{Duration: 0.0, Title: ""}},
{false, "#EXTINF:10.000", false, &MediaSegment{Duration: 10.0, Title: ""}},
{false, "#EXTINF:10.000,", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: ""}},
{false, "#EXTINF:10.000,Title", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: "Title"}},
{false, "#EXTINF:10.000,Title,Track", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: "Title,Track"}},
{false, "#EXTINF:invalid,", false, &MediaSegment{Duration: 0.0, URI: "/s.ts", Title: ""}},
{false, "#EXTINF:10.000", false, &MediaSegment{Duration: 10.0, URI: "/s.ts", Title: ""}},
}

for _, test := range tests {
Expand Down