fix: resolve RSS feed validation errors#451
Conversation
- Use <dc:creator> instead of <author> for item authors RSS 2.0 spec requires <author> to be an email address; the dc namespace is already declared and <dc:creator> is the correct element for names. - Fix double-encoded HTML entities in title and description MkDocs pre-escapes content, then Jinja's |e filter escapes again, producing &amp;, &lt;, &gt;. Added replace filters to correct the double-encoding. - Guard <enclosure> against None/non-positive length values When a remote image returns 404, the length field becomes None, producing invalid XML. Added guard to skip enclosure when length is None or non-positive.
- Switch to Zerthick/mkdocs-rss-plugin@fix/rss-validation-errors fork which includes upstream PR: Guts/mkdocs-rss-plugin#451 - Remove fix_rss_template.py workaround script (no longer needed) - Remove RSS template patch step from CI workflow Fixes included in fork: - <author> -> <dc:creator> for RSS 2.0 compliance - Guard enclosure length against None values - Fix double-encoded HTML entities in title/description
|
Thanks you and your LLM for this contribution but can you ask it to comply with contributing guidelines please? Also, are you sure that changes are relevant? Can you share your prompt and give an idea about the level of AI involvement here please? |
- Use <dc:creator> instead of <author> for item authors RSS 2.0 spec requires <author> to be an email address; the dc namespace is already declared and <dc:creator> is the correct element for names. - Fix double-encoded HTML entities in title/description MkDocs pre-escapes content, then Jinja's |e filter escapes again. Unescape in Python (html_module.unescape) before template rendering so |e performs a single correct escape. - Guard <enclosure> against None/non-positive length values When a remote image returns 404, the length field becomes None, producing invalid XML. Added guard to skip enclosure when length is None or non-positive. - Add tests for all three fixes (test_rss_validation.py) Includes page_with_special_chars.md fixture with & < > characters.
|
I'm using Material for MkDocs for my own personal blog, I noticed 3 distinct errors in my RSS feed when put in a validator such as: https://www.rssboard.org/rss-validator/ The author issue seems to be a longstanding one: #192 Material for MkDocs typically uses a human readable name for the author, not an email causing validation to fail. The other two seemed to be edge cases I encountered. Such as having a Based on that scale I'd say this is a Level 8 contribution. I did not have a specific prompt, I gave my LLM the errors I was receiving in the validator and told it to resolve them, applied it's fixes, re-validated the feed, until all the errors were resolved. I can confirm that the forked version is working correctly on my blog now and has resolved the feed and formatting issues I was observing before. https://www.datadelver.com/feed_rss_created.xml I prompted my LLM to add unit tests, are there any other specific modifications to the PR you would like to see? |
|
|
@Guts You can view some of these validation errors on your own feed as well:
|




Summary
Fixes three RSS 2.0 validation errors in the generated feed.
Changes
1.
<author>→<dc:creator>for item authors (template)The RSS 2.0 spec requires
<author>to be an email address (e.g.,user@example.com). The plugin was using it for display names, which causes validation failures on every feed validator. Switched to<dc:creator>which is the correct element for human-readable names—thedcnamespace is already declared in the template.Before:
<author>John Doe</author>After:
<dc:creator>John Doe</dc:creator>2. Fix double-encoded HTML entities in title/description (Python)
MkDocs pre-escapes page titles and descriptions, then Jinja's
|efilter escapes them again, producing&amp;,&lt;,&gt;instead of&,<,>.Fixed by unescaping in Python (
html.unescape()) before passing to the template, so Jinja's|eperforms a single correct escape. This is cleaner than template-level workarounds and benefits both RSS and JSON feeds.Before:
&amp;(double-encoded)After:
&(correctly encoded)3. Guard
<enclosure>against None/non-positive length (template)When the plugin fetches a remote image that returns 404, the length field becomes
None, producing invalid XML like<enclosure length="None" />. Added a guard to skip the enclosure element when length is None or non-positive.Before:
{% if item.image is not none %}After:
{% if item.image is not none and item.image[2] is not none and item.image[2] > 0 %}Tests
Added
tests/test_rss_validation.pywith three tests covering all fixes:test_dc_creator_instead_of_authortest_no_double_encoded_entitiestest_enclosure_guard_none_lengthPlus
tests/fixtures/docs/page_with_special_chars.mdfixture with& < >characters.Impact
<dc:creator>is a standard RSS extension already supported by all feed readers