Block supports: Fix block attribute (style and class) double-encoding#25079
Merged
Block supports: Fix block attribute (style and class) double-encoding#25079
Conversation
|
Size Change: 0 B Total Size: 1.2 MB ℹ️ View Unchanged
|
Addison-Stavlo
approved these changes
Sep 4, 2020
Contributor
Addison-Stavlo
left a comment
There was a problem hiding this comment.
This change looks good to me (especially after considering the detailed description of why we don't need to use esc_attr here #25079 (comment)), and does fix the double encoding issue.
Thanks @sirreal !
P.S. Do you think it makes sense to add a small comment somewhere regarding the need (or lack of) for esc_attr? This approach is still fairly new and if it is changed to no longer user DOMDocument && setAttribute (due to any concerns with performance or any other issues that may be found), the need to use esc_attr may arise again?
sirreal
commented
Sep 4, 2020
youknowriad
pushed a commit
that referenced
this pull request
Sep 7, 2020
…#25079) * Add encoding tests * Remove double attribute value escaping * fixup! Add encoding tests * Add escaping comment
6 tasks
Contributor
|
Oof, thanks for fixing this! |
11 tasks
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
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.
Description
Remove double encoding of class and style attributes in block supports.
Dynamic blocks rendered by block-supports double encode html which may produce broken results. For example, if we start with valid HTML including a single quote (apostrophe) in a double-quoted attribute, the single quote will be encoded by
esc_attrto the unicode HTML entity'.DOMElement::setAttributewill then encode this result to'. This single entity is now doubly encoded and will be interpreted by the browser as'. A full example:When this finally reaches the browser, it makes a request for the background image to the relative path
&because the unescaped url is interpreted as'https://example.com/image.png'.I've added unit tests which attempt to clarify and verify the expected behavior, we can observe the double encoding in the failed unit tests on the first commit of this PR.
This behavior was introduced in #24486.
How has this been tested?
Unit tests.
Manual testing.
Types of changes
Bug fix: Fix double-encoding of dynamic block classes and styles.
Checklist: