From 6c59df6bd8ba628fd4c5ac1b5b64ca4f394cc3b7 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Sun, 14 Feb 2016 20:15:53 +0100 Subject: [PATCH] Bugfix early ending end tag --- html/html.go | 8 ++++++-- html/html_test.go | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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=""`}, + {`