diff --git a/vmap/decoder.go b/vmap/decoder.go index 3f5feba..78163c3 100644 --- a/vmap/decoder.go +++ b/vmap/decoder.go @@ -130,6 +130,9 @@ func (adBreak *AdBreak) UnmarshalToken(tok *xmltokenizer.Tokenizer, se *xmltoken switch string(token.Name.Local) { case "VAST": var vast VAST + if token.SelfClosing { + break + } // Reuse Token object in the sync.Pool since we only use it temporarily. se := xmltokenizer.GetToken().Copy(token) err = vast.UnmarshalToken(tok, se) diff --git a/vmap/sample-vmap/testVmapEmptyVast.xml b/vmap/sample-vmap/testVmapEmptyVast.xml new file mode 100644 index 0000000..554499f --- /dev/null +++ b/vmap/sample-vmap/testVmapEmptyVast.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/vmap/structure_test.go b/vmap/structure_test.go index 8bb245c..27a2f28 100644 --- a/vmap/structure_test.go +++ b/vmap/structure_test.go @@ -62,6 +62,17 @@ func TestDecodeEmptyVmap(t *testing.T) { is.Equal(len(vmap.AdBreaks), 0) } +func TestDecodeVmapEmptyVast(t *testing.T) { + is := is.New(t) + doc, err := os.ReadFile("sample-vmap/testVmapEmptyVast.xml") + is.NoErr(err) + + vmap, err := DecodeVmap(doc) + is.NoErr(err) + + is.Equal(len(vmap.AdBreaks), 1) +} + func TestDecodeEmptyVast(t *testing.T) { is := is.New(t) doc, err := os.ReadFile("sample-vmap/testVast3.xml")