WordPress.org

Make WordPress Core

Changeset 47169


Ignore:
Timestamp:
02/03/2020 12:12:22 AM (5 months ago)
Author:
SergeyBiryukov
Message:

Canonical: When removing trailing punctuation from query string arguments, match the whole query var name.

Props daveslaughter.
Fixes #49347.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r47122 r47169  
    486486    if ( ! empty( $redirect['query'] ) ) {
    487487        // Remove trailing spaces and end punctuation from certain terminating query string args.
    488         $redirect['query'] = preg_replace( "#((p|page_id|cat|tag)=[^&]*?)($punctuation_pattern)+$#", '$1', $redirect['query'] );
     488        $redirect['query'] = preg_replace( "#((^|&)(p|page_id|cat|tag)=[^&]*?)($punctuation_pattern)+$#", '$1', $redirect['query'] );
    489489
    490490        // Clean up empty query strings.
  • trunk/tests/phpunit/tests/canonical/noRewrite.php

    r47122 r47169  
    3535         * [1]: Expected results: Any of the following can be used.
    3636         *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
    37          *      array( expected query vars to be set, same as 'qv' above )
    38          *      (string) expected redirect location
    39          * [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
     37         *      array( expected query vars to be set, same as 'qv' above );
     38         *      (string) expected redirect location.
     39         * [3]: (optional) The ticket the test refers to. Can be skipped if unknown.
    4040         */
    4141        return array(
     
    268268            array( '/page/2/%E2%80%9D', '/page/2/', 20383 ), // Encoded closing curly quote.
    269269
    270             array( '/?page_id=1', '/?p=1' ), // Redirect page_id to p (should cover page_id|p|attachment_id to one another.
     270            array( '/?page_id=1', '/?p=1' ), // Redirect page_id to p (should cover page_id|p|attachment_id to one another).
    271271            array( '/?page_id=1&post_type=revision', '/?p=1' ),
    272272
    273273            array( '/?feed=rss2&p=1', '/?feed=rss2&p=1', 21841 ),
    274274            array( '/?feed=rss&p=1', '/?feed=rss2&p=1', 24623 ),
     275
     276            array( '/?comp=East+(North)', '/?comp=East+(North)', 49347 ),
    275277        );
    276278    }
Note: See TracChangeset for help on using the changeset viewer.