Skip to content

fix(html): keep the rest of a title after a character reference - #427

Open
rajanpanth wants to merge 1 commit into
openzim:mainfrom
rajanpanth:fix/html-title-entities
Open

rajanpanth wants to merge 1 commit into
openzim:mainfrom
rajanpanth:fix/html-title-entities

Conversation

@rajanpanth

Copy link
Copy Markdown

Summary

  • HtmlRewriter.rewrite().title kept only the text before the first & because the parser leaves character references encoded and then stored the first piece of the title.
  • rewrite() already needed a parsed document for the base href. It now builds that tree once and reads both the base href and the first <title> from it, so entities are decoded without a second parse.
  • An empty first <title> stays empty, including when a later SVG title exists. That matches document.title. The rewritten HTML is unchanged.

Fixes #401

Test plan

  • pytest tests/rewriting/test_html_rewriting.py::test_extract_title tests/rewriting/test_html_rewriting.py::test_title_keeps_text_after_character_references tests/rewriting/test_html_rewriting.py::test_extract_base_href
  • Rewrite a page titled Tom &amp; Jerry and confirm the ZIM title is Tom & Jerry while the HTML still contains &amp;

Made with Cursor

The rewriter parsed titles with character references left encoded, so only the text before the first ampersand was kept.

Co-authored-by: Cursor <[email protected]>

This branch has not been deployed

No deployments
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.

HtmlRewriter: title is cut at the first & (entity or bare ampersand)

1 participant