-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block supports: Fix block attribute (style and class) double-encoding #25079
Conversation
Size Change: 0 B Total Size: 1.2 MB ℹ️ View Unchanged
|
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.
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?
…#25079) * Add encoding tests * Remove double attribute value escaping * fixup! Add encoding tests * Add escaping comment
Oof, thanks for fixing this! |
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_attr
to the unicode HTML entity'
.DOMElement::setAttribute
will 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: