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

Fix eager doctype regex matching #764

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Conversation

UVMvmfee
Copy link
Contributor

@UVMvmfee UVMvmfee commented Dec 7, 2024

This fixes a bug encountered in the wild: repair_faulty_html() tries to match malformed doctype tags assuming the doctype to be followed by a newline. If there actually is no newline then the regex matches too eager, and parts of the document are removed erroneously.

A reduced test case is
<!DOCTYPE html><html><head></head><body>Foo <br/> Bar</body></html> which would be reduced to Bar</body></html> without the fix.

This PR adds a reduced test case and tries to fix eagerness by keeping the regex in tag bounderies. pytest shows no regressions.

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.27%. Comparing base (7067937) to head (7671f3d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #764   +/-   ##
=======================================
  Coverage   99.27%   99.27%           
=======================================
  Files          21       21           
  Lines        3572     3572           
=======================================
  Hits         3546     3546           
  Misses         26       26           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adbar
Copy link
Owner

adbar commented Dec 9, 2024

@UVMvmfee That's correct, thanks for the fix.

@adbar adbar merged commit ad30d66 into adbar:master Dec 9, 2024
15 checks passed
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

Successfully merging this pull request may close these issues.

2 participants