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 14, 2016
1 parent 18fd303 commit 6c59df6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
}

if t.TokenType == html.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
}
break
Expand Down
4 changes: 4 additions & 0 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ func TestHTML(t *testing.T) {
{`<a id="abc" name="abc">y</a>`, `<a id=abc>y</a>`},
{`<a id="" value="">y</a>`, `<a value>y</a>`},

// from Kangax html-minfier
{`<span style="font-family:&quot;Helvetica Neue&quot;,&quot;Helvetica&quot;,Helvetica,Arial,sans-serif">text</span>`, `<span style='font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif'>text</span>`},

// go-fuzz
{`<meta e t n content=ful><a b`, `<meta e t n content=ful><a b>`},
{`<img alt=a'b="">`, `<img alt='a&#39;b=""'>`},
{`</b`, `</b`},
}

m := minify.New()
Expand Down

0 comments on commit 6c59df6

Please sign in to comment.