Repository navigation
fix: resolve double-encoded HTML entities in title and description - #456
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #456 +/- ##
==========================================
+ Coverage 83.20% 83.22% +0.02%
==========================================
Files 11 11
Lines 786 787 +1
Branches 133 133
==========================================
+ Hits 654 655 +1
Misses 86 86
Partials 46 46
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Guts
left a comment
There was a problem hiding this comment.
Thanks for this one.
The description part, however, introduces a regression, and the test doesn't exercise the bug:
-
descriptionis HTML, not text :get_description_or_abstract()returnspage.contentormarkdown.markdown(...)output in almost every branch, and the JSON Feed publishes it ascontent_html. In RSS,<description>carries that HTML escaped once for XML, so&lt;in the raw XML is the correct encoding of a<in the HTML. Unescaping it first turns code samples into real markup. WithUse `<script>` and `a < b` in code.:main: readers get<p>Use <code><script></code> and <code>a < b</code> in code.</p>- this PR: readers get
<p>Use <code><script></code> and <code>a < b</code> in code.</p>
For a docs plugin, where inline code is everywhere, that's a blocker. Please keep the unescape on
titleonly (see inline suggestions). -
fixture doesn't reproduce the bug because its title is set in the front-matter, which MkDocs returns verbatim; only H1-derived titles carry entities. Same for the
descriptionmeta, which|ealready escapes once. The new test passes onmainwithout the fix. I've suggested a fixture with an H1 title instead.
Please also rebase on main.
ada0a8d to
5214af7
Compare
|
Done:
|
|
@Zerthick thanks. Can you rebase again on tour side please? |
MkDocs pre-escapes content, then Jinja's |e filter escapes again, producing &amp;, &lt;, &gt;. Use html.unescape() in Python before template rendering so |e performs a single correct escape. - Add html_module.unescape() for title and description in plugin.py - Add test fixture with special characters - Add test verifying no double-encoded entities
- keep unescape on title only: description is HTML and must stay escaped once, unescaping it turned code samples into real markup - fixture: derive the title from the H1 so it actually carries entities (front-matter titles are returned verbatim by MkDocs) - drop the duplicate test module; assert the title encoding in test_xml_escaping_in_author
5214af7 to
fa8485b
Compare
|



Description
Resolve double-encoded HTML entities (e.g.
&amp;,&lt;,&gt;) in RSS feed title and description fields.MkDocs pre-escapes content, and then Jinja's
|efilter escapes again, producing double-encoded entities. Usinghtml.unescape()in Python before template rendering ensures|eperforms a single correct escape.Changes
html_module.unescape()for title and description inplugin.py& < >)Split from: #451