Skip to content

Commit

Permalink
HTML: fix spacing around <script></script>; fixes #592
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jul 23, 2023
1 parent 50df8e4 commit 1d436e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
}

// keep space after phrasing tags (<i>, <span>, ...) FontAwesome etc.
if t.TokenType == html.StartTagToken && t.Traits&nonPhrasingTag == 0 {
if t.TokenType == html.StartTagToken && t.Traits == normalTag {
if next := tb.Peek(0); next.Hash == t.Hash && next.TokenType == html.EndTagToken {
omitSpace = false
}
Expand Down
29 changes: 15 additions & 14 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,21 @@ func TestHTML(t *testing.T) {
{`<script><!--<`, `<script><!--<`},

// bugs
{`<svg id="1"></svg>`, `<svg id="1"></svg>`}, // #67
{`<pre> <x> a b </x> </pre>`, `<pre> <x> a b </x> </pre>`}, // #82
{`text <progress></progress> text`, `text <progress></progress> text`}, // #89
{`text <img> text`, `text <img> text`}, // #89
{`<p>text</p><br>text`, `<p>text</p><br>text`}, // #122
{`<amp-analytics type=adobeanalytics_nativeConfig>`, `<amp-analytics type=adobeanalytics_nativeConfig>`}, // #270
{`<input title=""><input lang="">`, `<input title><input lang>`}, // #331
{`<span translate="no">`, `<span translate=no>`}, // #352
{`<i class="fas"> </i> Text`, `<i class=fas></i>Text`}, // #390
{`<i class="fas"></i> Text`, `<i class=fas></i> Text`}, // #390
{`a <span></span> b`, `a <span></span> b`}, // #427
{`<canvas><p>test</p></canvas>`, `<canvas><p>test</p></canvas>`}, // #440
{`<source type='video/mp4; codecs="av01.0.05M.08"'>`, `<source type='video/mp4;codecs="av01.0.05M.08"'>`}, // #545
{`<html lang="mn-Cyrl-MN">`, `<html lang=mn-Cyrl-MN>`}, // #579
{`<svg id="1"></svg>`, `<svg id="1"></svg>`}, // #67
{`<pre> <x> a b </x> </pre>`, `<pre> <x> a b </x> </pre>`}, // #82
{`text <progress></progress> text`, `text <progress></progress> text`}, // #89
{`text <img> text`, `text <img> text`}, // #89
{`<p>text</p><br>text`, `<p>text</p><br>text`}, // #122
{`<amp-analytics type=adobeanalytics_nativeConfig>`, `<amp-analytics type=adobeanalytics_nativeConfig>`}, // #270
{`<input title=""><input lang="">`, `<input title><input lang>`}, // #331
{`<span translate="no">`, `<span translate=no>`}, // #352
{`<i class="fas"> </i> Text`, `<i class=fas></i>Text`}, // #390
{`<i class="fas"></i> Text`, `<i class=fas></i> Text`}, // #390
{`a <span></span> b`, `a <span></span> b`}, // #427
{`<canvas><p>test</p></canvas>`, `<canvas><p>test</p></canvas>`}, // #440
{`<source type='video/mp4; codecs="av01.0.05M.08"'>`, `<source type='video/mp4;codecs="av01.0.05M.08"'>`}, // #545
{`<html lang="mn-Cyrl-MN">`, `<html lang=mn-Cyrl-MN>`}, // #579
{`<script src=a></script> <script src=b></script> <span></span>`, `<script src=a></script><script src=b></script><span></span>`}, // #592
}

m := minify.New()
Expand Down

0 comments on commit 1d436e3

Please sign in to comment.