Skip to content

Commit 6c59df6

Browse files
committed
Bugfix early ending end tag
1 parent 18fd303 commit 6c59df6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

html/html.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,12 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
221221
}
222222

223223
if t.TokenType == html.EndTagToken {
224-
t.Data[2+len(t.Text)] = '>'
225-
if _, err := w.Write(t.Data[:2+len(t.Text)+1]); err != nil {
224+
if len(t.Data) > 2+len(t.Text) {
225+
t.Data[2+len(t.Text)] = '>'
226+
if _, err := w.Write(t.Data[:2+len(t.Text)+1]); err != nil {
227+
return err
228+
}
229+
} else if _, err := w.Write(t.Data); err != nil {
226230
return err
227231
}
228232
break

html/html_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ func TestHTML(t *testing.T) {
109109
{`<a id="abc" name="abc">y</a>`, `<a id=abc>y</a>`},
110110
{`<a id="" value="">y</a>`, `<a value>y</a>`},
111111

112+
// from Kangax html-minfier
113+
{`<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>`},
114+
112115
// go-fuzz
113116
{`<meta e t n content=ful><a b`, `<meta e t n content=ful><a b>`},
114117
{`<img alt=a'b="">`, `<img alt='a&#39;b=""'>`},
118+
{`</b`, `</b`},
115119
}
116120

117121
m := minify.New()

0 commit comments

Comments
 (0)