Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped < characters (&lt;) are processed incorrectly #191

Open
chrispy-snps opened this issue Jun 7, 2024 · 2 comments
Open

Escaped < characters (&lt;) are processed incorrectly #191

chrispy-snps opened this issue Jun 7, 2024 · 2 comments

Comments

@chrispy-snps
Copy link

chrispy-snps commented Jun 7, 2024

This is a more specific follow-up to #182.

When the &lt; escape sequence is processed, it is incorrectly converted to &LT instead of kept as-is:

>>> import minify_html
>>> print(minify_html_onepass.minify("&lt;"))
<

>>> print(minify_html_onepass.minify("&lt;faketag"))
&LTfaketag

>>> print(minify_html_onepass.minify("&lt;faketag&gt;"))
&LTfaketag>

Strangely, a bare &lt; by itself is processed correctly. It is only when followed by content that it breaks.

The issue occurs in both minify_html and minify_html_onepass.

We are able to work around it as follows:

html = html.replace("&lt;", "AMP_LT_WORKAROUND")
html_minified = minify_html.minify(html)
html = html.replace("AMP_LT_WORKAROUND", "&lt;")

but a proper fix would be better (and more efficient, as we process tens of thousands of HTML files at a time).

@codingjerk
Copy link

Hi @chrispy-snps, thank you for workaround

@Rongronggg9
Copy link

See also #109 and #139.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants