-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Block supports: Avoid warning for non string class attributes #5486
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: Avoid warning for non string class attributes #5486
Conversation
|
@dmsnell 10 |
482f394 to
bce9b11
Compare
|
Could the tests be failing because the markup is missing a closing div? To an extent I'm asking the silly question because I'd sure feel silly if I didn't and it turned out to be the case ;) |
|
@peterwilsoncc no, and I wasn't sure what happened. I tried a few things that I thought should fix it, so I'm curious when my change is at fault or if the implicit behavior this removed is at fault, even though from the unit tests it looks like it should be fine. |
75092c5 to
0c6e8e7
Compare
0c6e8e7 to
797c0fa
Compare
sirreal
left a comment
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 needs to be updated, but generally looks like a good fix for some subtle issues.
| $updated_style = ''; | ||
|
|
||
| if ( ! empty( $existing_style ) ) { | ||
| if ( is_string( $existing_style ) && ! empty( $existing_style ) ) { |
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 for reviewers: the empty on this line would not have any issues, but would do the wrong thing if passed true, ! empty( true ) evaluates to true, so this block would be entered if if $existing_style is true, for example with HTML like <div style>. Inside the block, $existing_style is expected to be a string and is passed to string methods.
797c0fa to
7ae9381
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
I have removed the added tests since I had trouble figuring out what the function should be doing, and since it seemed like they didn’t add much value anyway. The existing tests verify the passing behaviors and will catch regressions. This patch only adds a bit of safety to handle some edge cases and therefore need not be distracted by asserting that those edge cases fail. |
6edbeb1 to
4c1a0f5
Compare
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`.
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`.
…ute as string. When encountering HTML tags with boolean or missing tags, the `get_attribute()` method in the HTML API returns `true` and `null`, resepectively. If these returned values are sent directly into string comparison functions then as of PHP 8.0 they will throw `E_DEPRECATED` errors. In this patch, block supports is enhanced to check that the `class` value is a string before it performs string operations on it.
4c1a0f5 to
3ba1e75
Compare
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Github-PR: 71594 Github-PR-URL: #71594 Branch-name: backport/block-supports-background-non-string-attribute-check
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Github-PR: 71594 Github-PR-URL: #71594 Branch-name: backport/block-supports-background-non-string-attribute-check
…ute as string. When encountering HTML tags with boolean or missing tags, the get_attribute() method in the HTML API returns true and null, respectively. If these returned values are sent directly into string comparison functions then as of PHP 8.0 they will throw E_DEPRECATED errors. In this patch, block supports is enhanced to check that the class value is a string before it performs string operations on it. Also in this patch: using `assertEqualHTML()` in background support test instead of `assertSame()` Developed in #5486 Discussed in https://core.trac.wordpress.org/ticket/59622 Props dmsnell, jonsurrell, hellofromtonya, peterwilsoncc. Fixes #59622. git-svn-id: https://develop.svn.wordpress.org/trunk@60727 602fd350-edb4-49c9-b593-d223f7449a82
…ute as string. When encountering HTML tags with boolean or missing tags, the get_attribute() method in the HTML API returns true and null, respectively. If these returned values are sent directly into string comparison functions then as of PHP 8.0 they will throw E_DEPRECATED errors. In this patch, block supports is enhanced to check that the class value is a string before it performs string operations on it. Also in this patch: using `assertEqualHTML()` in background support test instead of `assertSame()` Developed in WordPress/wordpress-develop#5486 Discussed in https://core.trac.wordpress.org/ticket/59622 Props dmsnell, jonsurrell, hellofromtonya, peterwilsoncc. Fixes #59622. Built from https://develop.svn.wordpress.org/trunk@60727 git-svn-id: http://core.svn.wordpress.org/trunk@60063 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…ute as string. When encountering HTML tags with boolean or missing tags, the get_attribute() method in the HTML API returns true and null, respectively. If these returned values are sent directly into string comparison functions then as of PHP 8.0 they will throw E_DEPRECATED errors. In this patch, block supports is enhanced to check that the class value is a string before it performs string operations on it. Also in this patch: using `assertEqualHTML()` in background support test instead of `assertSame()` Developed in WordPress/wordpress-develop#5486 Discussed in https://core.trac.wordpress.org/ticket/59622 Props dmsnell, jonsurrell, hellofromtonya, peterwilsoncc. Fixes #59622. Built from https://develop.svn.wordpress.org/trunk@60727 git-svn-id: https://core.svn.wordpress.org/trunk@60063 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Github-PR: 71594 Github-PR-URL: #71594 Branch-name: backport/block-supports-background-non-string-attribute-check
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Github-PR: 71594 Github-PR-URL: #71594 Branch-name: backport/block-supports-background-non-string-attribute-check Trac-ticket: 59622
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Github-PR: 71594 Github-PR-URL: WordPress#71594 Branch-name: backport/block-supports-background-non-string-attribute-check Trac-ticket: 59622
Trac ticket: Core-59622 This is a backport of WordPress/wordpress-develop#5486, which introduces an additional check for non-string values of the `class` attribute when rendering background support for blocks. This check avoids issuing a warning when a boolean `true` value of the attribute is passed on to `str_ends_with()`. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Github-PR: 71594 Github-PR-URL: WordPress/gutenberg#71594 Branch-name: backport/block-supports-background-non-string-attribute-check Trac-ticket: 59622 Source: WordPress/gutenberg@54564ab
…ute as string. When encountering HTML tags with boolean or missing tags, the get_attribute() method in the HTML API returns true and null, respectively. If these returned values are sent directly into string comparison functions then as of PHP 8.0 they will throw E_DEPRECATED errors. In this patch, block supports is enhanced to check that the class value is a string before it performs string operations on it. Also in this patch: using `assertEqualHTML()` in background support test instead of `assertSame()` Developed in WordPress#5486 Discussed in https://core.trac.wordpress.org/ticket/59622 Props dmsnell, jonsurrell, hellofromtonya, peterwilsoncc. Fixes #59622. git-svn-id: https://develop.svn.wordpress.org/trunk@60727 602fd350-edb4-49c9-b593-d223f7449a82
Trac ticket: Core-59622
Gutenberg backport: WordPress/gutenberg#71594
Block Supports: Avoid throwing warning when checking for class attribute as string.
When encountering HTML tags with boolean or missing tags, the
get_attribute()method in the HTML API returns
trueandnull, respectively. If these returnedvalues are sent directly into string comparison functions then as of PHP 8.0 they
will throw
E_DEPRECATEDerrors.In this patch, block supports is enhanced to check that the
classvalue is astring before it performs string operations on it.
There is a small likelihood of any real damage in production here, as these are only deprecation notices and the logic in these cases isn't affected by the change. That is,
the intention of the code is maintained even when the attribute values aren't strings.
For background support there's a tiny but benign defect when the
styleattribute isboolean. It will erroneously inject a
;at the beginning of the wrapper's newstylevalue. As this doesn't impact the rendering of the wrapper, it's not a true defect.
Further review belongs to block rendering code, but this will occur in the Gutenberg
repo since that PHP comes back into Core through the generated packages.
Testing
There should be no functional or visual changes in this patch. Please consult blocks with layout and background support to verify that this hasn't adversely affected existing rendering. Verify that the test suite continues to pass.