terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
385 stars 32 forks source link

Is this expected --collapse-inline-tag-whitespace behavior? #179

Open juj opened 3 months ago

juj commented 3 months ago

What happened?

Take the following test.html:

<html><body>
The quick brown fox <a href='https://en.wikipedia.org/wiki/Jump'>jumps</a> over the lazy dog
</body></html>

Run it through

html-minifier-terser --collapse-whitespace --collapse-inline-tag-whitespace test.html

This will result in:

<html><body>The quick brown fox<a href="https://en.wikipedia.org/wiki/Jump">jumps</a>over the lazy dog</body></html>

When this page is rendered by the browser, the result is that the words foxjumpsover are joined together to become unreadable.

Is that intentional for the --collapse-inline-tag-whitespace pass? Or somehow an accident, and this pass should only apply to other kinds of elements?

I am asking since the above transform makes this change seem like a fundamentally unsafe optimization? In another ticket, users are pondering if that is a bug.

If this is intentional, it may be worthwhile to add a comment in the docs of the pass that this optimization can have undesirable results?

Version

7.2.0

What browsers are you seeing the problem on?

No response

Link to reproduce

No response

Relevant log output

No response

Willing to submit a PR?

None

DanielRuf commented 3 weeks ago

a is an inline element as specified at https://github.com/terser/html-minifier-terser/blob/master/src/htmlminifier.js#L64-L67

Is that intentional for the --collapse-inline-tag-whitespace pass?

Probably.

DanielRuf commented 2 weeks ago

I think conservativeCollapse: true should resolve this.