From 0ee301faef5b7ac36ce4edc4259a2b73aec521e8 Mon Sep 17 00:00:00 2001 From: "Eric M. Johnston" Date: Tue, 21 Dec 2021 22:18:57 -0500 Subject: [PATCH] Ignore blank lines in playlist -- fixes panic w/EXT-X-MAP. --- reader.go | 2 ++ reader_test.go | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/reader.go b/reader.go index b19324eb..1a195cfa 100644 --- a/reader.go +++ b/reader.go @@ -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 diff --git a/reader_test.go b/reader_test.go index 8d60b16c..c2579324 100644 --- a/reader_test.go +++ b/reader_test.go @@ -344,6 +344,7 @@ func TestDecodeMediaPlaylistExtInfNonStrict2(t *testing.T) { #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 %s +/s.ts ` tests := []struct { @@ -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 {