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

Fix panic on empty lines #202

Open
wants to merge 3 commits 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
8 changes: 8 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st

line = strings.TrimSpace(line)

if line == "" {
return nil
}

// check for custom tags first to allow custom parsing of existing tags
if p.Custom != nil {
for _, v := range p.customDecoders {
Expand Down Expand Up @@ -451,6 +455,10 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l

line = strings.TrimSpace(line)

if line == "" {
return nil
}

// check for custom tags first to allow custom parsing of existing tags
if p.Custom != nil {
for _, v := range p.customDecoders {
Expand Down
21 changes: 21 additions & 0 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
path
`

tests := []struct {
Expand Down Expand Up @@ -383,6 +384,7 @@ func TestDecodeMediaPlaylistExtInfNonStrict2(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
test.wantSegment.URI = "path"
if !reflect.DeepEqual(p.Segments[0], test.wantSegment) {
t.Errorf("\nhave: %+v\nwant: %+v", p.Segments[0], test.wantSegment)
}
Expand Down Expand Up @@ -972,6 +974,25 @@ func TestDecodeMediaPlaylistStartTime(t *testing.T) {
}
}

func TestDecodeMediaPlaylistDicontinuityAtBegin(t *testing.T) {
f, err := os.Open("sample-playlists/media-with-discontinuity-at-start.m3u8")
if err != nil {
t.Fatal(err)
}
p, listType, err := DecodeFrom(bufio.NewReader(f), true)
if err != nil {
t.Fatal(err)
}
pp := p.(*MediaPlaylist)
CheckType(t, pp)
if listType != MEDIA {
t.Error("Sample not recognized as media playlist.")
}
if pp.StartTime != float64(0.0) {
t.Errorf("Media segment StartTime != 0: %f", pp.StartTime)
}
}

/****************
* Benchmarks *
****************/
Expand Down
13 changes: 13 additions & 0 deletions sample-playlists/media-with-discontinuity-at-start.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#EXTM3U
#EXT-X-VERSION:5
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:7
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-KEY:METHOD=AES-128,URI="data:text/plain;charset=utf-8,a4cd9995a1aa91e1",IV=0x30303030303030303030303030303030

#EXT-X-DISCONTINUITY

#EXT-X-PROGRAM-DATE-TIME:1979-05-02T13:33:23.089999973Z
#EXTINF:6.910,
294500000/294500000/6778687.ts
#EXT-X-ENDLIST