-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Widgets: Decode HTML entities in widget RSS title before escaping #9042
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
Open
Infinite-Null
wants to merge
5
commits into
WordPress:trunk
Choose a base branch
from
Infinite-Null:fix/rss-widget-html-entities
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5363661
Fix: Decode HTML entities in widget RSS title before escaping
Infinite-Null 13b4924
fix: Decode HTML entities in RSS item titles before escaping
Infinite-Null 71c1ca0
fix: Remove unnecessary HTML entity decoding from RSS item titles
Infinite-Null e469162
test: Add unit test for HTML entities decoding in RSS title output
Infinite-Null 959c8aa
Merge branch 'trunk' into fix/rss-widget-html-entities
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh. we have a hard time separating XML and HTML. RSS makes it even more complicated because it’s not required to be a valid XML file and they usually don’t indicate how we should be interpreting the characters inside the different elements.
here is what comes from the linked feed. it’s obvious they have sent encoded content inside the
titleelement.this brings us to an odd spot. if we follow this logic we are missing a second
html_entity_decode(), and the first one is wrong. the first level is decoding XML, where HTML named character references are not valid. that produces the HTML of the item’s title. then we want to decode the item’s title, revealing plaintext. but that title itself could have referenced something likedrug A is < drug Bin which case its HTML would bedrug A is < drug Bin which case the XML wrapping should escape that a second time intodrug A is &lt; drug B.we have decoded the XML into HTML and then removed tags, potentially leaving those same character references undecoded from the HTML side.
it may help to use additional variables, and I will recommend switching from
html_entity_decode()on the XML side into the HTML API on the HTML side. why this function works for XML and breaks for HTML is beyond my imagination, but alas, that’s the way it is.This function is old and could use a lot of love.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it’s very likely we could encounter other encodings of the
titleattribute. Fixing this could break others, because RSS is not explicit about the content type of the contained values.The above code could turn into some function explicitly indicating what it is assuming and used here. Should we decide to enhance the robustness later, we would have an easy way to assess the existing code and swap it out as appropriate.
and then call it
The same should likely apply to the description below as well. Why do we call
esc_attr( esc_html( $desc ) )🤦♂️ 😭.