Skip to content

Commit

Permalink
Revert "HTML: remove space between attributes after quoted value"
Browse files Browse the repository at this point in the history
This reverts commit 0260763, fixes #342
  • Loading branch information
tdewolff committed Oct 16, 2020
1 parent eb4ff2b commit c2f5ff6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
7 changes: 1 addition & 6 deletions html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
}

// write attributes
prevQuote := false
for {
attr := *tb.Shift()
if attr.TokenType != html.AttributeToken {
Expand Down Expand Up @@ -467,11 +466,8 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
}
}

if !prevQuote {
w.Write(spaceBytes)
}
w.Write(spaceBytes)
w.Write(attr.Text)
prevQuote = false
if len(val) > 0 && attr.Traits&booleanAttr == 0 {
w.Write(isBytes)

Expand All @@ -481,7 +477,6 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
// no quotes if possible, else prefer single or double depending on which occurs more often in value
val = html.EscapeAttrVal(&attrByteBuffer, attr.AttrVal, val, o.KeepQuotes || isXML)
w.Write(val)
prevQuote = val[0] == '"' || val[0] == '\''
}
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ func TestHTML(t *testing.T) {
{`<input type="radio" value="">`, `<input type=radio value>`},
{`<input type="radio" value="on">`, `<input type=radio>`},
{`<input type="text" value="">`, `<input>`},
{`<a b="x x" c="x x">`, `<a b="x x"c="x x">`},

// increase coverage
{`<script style="css">js</script>`, `<script style=css>js</script>`},
{`<script type="text/javascript">js</script>`, `<script>js</script>`},
{`<script type="application/javascript">js</script>`, `<script>js</script>`},
{`<meta http-equiv="content-type" content="text/plain, text/html">`, `<meta http-equiv=content-type content="text/plain,text/html">`},
{`<meta property="rdfa" content="data">`, `<meta property="rdfa"content="data">`},
{`<meta property="rdfa" content="data">`, `<meta property="rdfa" content="data">`},
{`<span attr=""></span>`, `<span attr></span>`},
{`<code>x</code>`, `<code>x</code>`},
{`<p></p><p></p>`, `<p><p>`},
Expand Down

0 comments on commit c2f5ff6

Please sign in to comment.