-
-
Notifications
You must be signed in to change notification settings - Fork 905
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: escape foreign style tag content when serializing HTML5 #3348
Merged
Conversation
This file contains 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
Normally, a `style` tag is considered to be a raw text element, meaning `<` is parsed as part of a possible "tag start" token, and is serialized literally (and not rendered as an escaped character reference `<`). However, when appearing in either SVG or MathML foreign content, a `style` tag should *not* be considered a raw text element, and should be escaped when serialized. libgumbo is parsing this case correctly, but our HTML5 serialization code does not escape the content. This commit updates the static `is_one_of()` C function to consider the namespace of the parent node as well as the tag's local name when deciding whether the tag matches the list of HTML elements, so that a `style` tag in foreign content will *not* match, but a `style` tag in HTML content will match.
This was referenced Dec 1, 2024
for v1.15.7 and v1.16.8
rgrove
added a commit
to rgrove/sanitize
that referenced
this pull request
Dec 26, 2024
This version of Nokogiri fixes a foreign content escaping issue that Sanitize previously had to work around manually. To avoid double escaping, Sanitize's workaround has been removed, which means it's important to prevent the use of an older Nokogiri that doesn't have the fix. See sparklemotion/nokogiri#3348
flavorjones
added a commit
that referenced
this pull request
Jan 2, 2025
**What problem is this PR intended to solve?** In #3348, downstream CI tests for Sanitize were temporarily disabled because the changes in that PR (intentionally) caused some of Sanitize's tests to fail. As of Sanitize 7.0.0, tests are passing again with the latest Nokogiri and it's safe to re-enable the downstream tests. 🎉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What problem is this PR intended to solve?
Normally, a
style
tag is considered to be a raw text element, meaning<
is parsed as part of a possible "tag start" token, and is serialized literally (and not rendered as an escaped character reference<
).However, when appearing in either SVG or MathML foreign content, a
style
tag should not be considered a raw text element, and should be escaped when serialized. libgumbo is parsing this case correctly, but our HTML5 serialization code does not escape the content.This commit updates the static
is_one_of()
C function to consider the namespace of the parent node as well as the tag's local name when deciding whether the tag matches the list of HTML elements, so that astyle
tag in foreign content will not match, but astyle
tag in HTML content will match.Have you included adequate test coverage?
Yes.
Does this change affect the behavior of either the C or the Java implementations?
HTML5 is only available in the CRuby impl.