Skip to content

Commit

Permalink
Bugfix: early ending end tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Feb 15, 2016
1 parent f558b7f commit bdad3ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion svg/svg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestSVG(t *testing.T) {
{`<!DOCTYPE bla><?xml?><!-- comment --><metadata/>`, ``},

{`<polygon fill="none" stroke="#000" points="-0.1,"/>`, `<polygon fill="none" stroke="#000" points="-0.1,"/>`}, // #45
{`</0`, `</0`}, // go fuzz
}

m := minify.New()
Expand Down
8 changes: 6 additions & 2 deletions xml/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
return err
}
case xml.EndTagToken:
t.Data[2+len(t.Text)] = '>'
if _, err := w.Write(t.Data[:2+len(t.Text)+1]); err != nil {
if len(t.Data) > 2+len(t.Text) {
t.Data[2+len(t.Text)] = '>'
if _, err := w.Write(t.Data[:2+len(t.Text)+1]); err != nil {
return err
}
} else if _, err := w.Write(t.Data); err != nil {
return err
}
}
Expand Down
2 changes: 2 additions & 0 deletions xml/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestXML(t *testing.T) {
{"<x a=\"&quot;&quot;'\"></x>", "<x a='\"\"&#39;'/>"},
{"<!DOCTYPE foo SYSTEM \"Foo.dtd\">", "<!DOCTYPE foo SYSTEM \"Foo.dtd\">"},
{"text <!--comment--> text", "text text"},

{`</0`, `</0`}, // go fuzz
}

m := minify.New()
Expand Down

0 comments on commit bdad3ed

Please sign in to comment.