Skip to content

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Aug 14, 2024

Add a strict argument to an in_array check that seems to be comparing strings with no need for loose comparison.

Follow-up to [58473].


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@@ -3667,7 +3667,7 @@ public function set_attribute( $name, $value ): bool {
*
* @see https://html.spec.whatwg.org/#attributes-3
*/
$escaped_new_value = in_array( $comparable_name, wp_kses_uri_attributes() ) ? esc_url( $value ) : esc_attr( $value );
$escaped_new_value = in_array( $comparable_name, wp_kses_uri_attributes(), true ) ? esc_url( $value ) : esc_attr( $value );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xknown, @aaronjorbin, @audrasjb This was added in https://core.trac.wordpress.org/changeset/58473 where you're propped. Can you confirm whether this loose in_array was intentional?

It seems like we want strict as we expect to be comparing strings, but I want to confirm first.

If we'd prefer to keep the loose comparison that's fine, I'd like to apply a different change because PHPCS is flagging this line as a warning now.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Would definitely be best to ensure that a filter for wp_kses_uri_attribute() doesn't introduce a value that casts to some string equivalent.

pento pushed a commit that referenced this pull request Aug 14, 2024
This patch modifies the URL-escaping code in the HTML API to rely on strict comparisons. This prevents accidental matching via type-coercion.

Developed in #7196

Follow-up to [58473].
Props jonsurrell.


git-svn-id: https://develop.svn.wordpress.org/trunk@58897 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Aug 14, 2024
This patch modifies the URL-escaping code in the HTML API to rely on strict comparisons. This prevents accidental matching via type-coercion.

Developed in WordPress/wordpress-develop#7196

Follow-up to [58473].
Props jonsurrell.

Built from https://develop.svn.wordpress.org/trunk@58897


git-svn-id: http://core.svn.wordpress.org/trunk@58293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@dmsnell
Copy link
Member

dmsnell commented Aug 14, 2024

Merged in [58897]
064f75e

@dmsnell dmsnell closed this Aug 14, 2024
@dmsnell dmsnell deleted the html-api/fix-loose-in-array-comparison branch August 14, 2024 19:52
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Aug 14, 2024
This patch modifies the URL-escaping code in the HTML API to rely on strict comparisons. This prevents accidental matching via type-coercion.

Developed in WordPress/wordpress-develop#7196

Follow-up to [58473].
Props jonsurrell.

Built from https://develop.svn.wordpress.org/trunk@58897


git-svn-id: https://core.svn.wordpress.org/trunk@58293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
aslamdoctor pushed a commit to aslamdoctor/wordpress-develop that referenced this pull request Dec 28, 2024
This patch modifies the URL-escaping code in the HTML API to rely on strict comparisons. This prevents accidental matching via type-coercion.

Developed in WordPress#7196

Follow-up to [58473].
Props jonsurrell.


git-svn-id: https://develop.svn.wordpress.org/trunk@58897 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants