diff --git a/html/html.go b/html/html.go index 6ba6877bda..3f216c1053 100644 --- a/html/html.go +++ b/html/html.go @@ -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 diff --git a/html/html_test.go b/html/html_test.go index 8b6151b515..7510d9fb2e 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -109,9 +109,13 @@ func TestHTML(t *testing.T) { {`y`, `y`}, {`y`, `y`}, + // from Kangax html-minfier + {`text`, `text`}, + // go-fuzz {``}, {`a'b=""`, `a'b=""`}, + {`