From a72c2ec610988130ae82e34cea4466a06a16457c Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Fri, 16 Feb 2024 21:39:35 -0300 Subject: [PATCH] HTML: keep original attribute quote for all attributes, fixes #670 --- go.mod | 2 +- go.sum | 4 ++-- html/html.go | 2 +- html/html_test.go | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 7e48193337..a2f85098f4 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/fsnotify/fsnotify v1.7.0 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 github.com/tdewolff/argp v0.0.0-20240126212256-acdb2fb50090 - github.com/tdewolff/parse/v2 v2.7.11 + github.com/tdewolff/parse/v2 v2.7.12 github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739 ) diff --git a/go.sum b/go.sum index 7e11c96b16..af53cfc99d 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 h1:JAEbJn3j/FrhdWA9jW8 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/tdewolff/argp v0.0.0-20240126212256-acdb2fb50090 h1:ok0U1tNDp9ICD93bMrZuFtHLwDoW+5nfSfF8e/x36Y0= github.com/tdewolff/argp v0.0.0-20240126212256-acdb2fb50090/go.mod h1:fF+gnKbmf3iMG+ErLiF+orMU/InyZIEnKVVigUjfriw= -github.com/tdewolff/parse/v2 v2.7.11 h1:v+W45LnzmjndVlfqPCT5gGjAAZKd1GJGOPJveTIkBY8= -github.com/tdewolff/parse/v2 v2.7.11/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= +github.com/tdewolff/parse/v2 v2.7.12 h1:tgavkHc2ZDEQVKy1oWxwIyh5bP4F5fEh/JmBwPP/3LQ= +github.com/tdewolff/parse/v2 v2.7.12/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739 h1:IkjBCtQOOjIn03u/dMQK9g+Iw9ewps4mCl1nB8Sscbo= diff --git a/html/html.go b/html/html.go index 1ccc85be53..ab50ff650b 100644 --- a/html/html.go +++ b/html/html.go @@ -504,7 +504,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st if 0 < len(attr.Data) && (attr.Data[len(attr.Data)-1] == '\'' || attr.Data[len(attr.Data)-1] == '"') { quote = attr.Data[len(attr.Data)-1] } - val = html.EscapeAttrVal(&attrByteBuffer, val, quote, o.KeepQuotes, isXML) + val = html.EscapeAttrVal(&attrByteBuffer, val, quote, o.KeepQuotes || isXML) w.Write(val) } } diff --git a/html/html_test.go b/html/html_test.go index 27a742daf8..31c9a8a514 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -142,7 +142,7 @@ func TestHTML(t *testing.T) { {`text`, `text`}, // go-fuzz - {``}, + {``}, {`a'b=""`, `a'b=""`}, {``, `

`}, {`

`, `

`}, {`

`, `

`}, + {``, ``}, } m := minify.New()