Make WordPress Core

Ticket #20383: 20383.2.patch

File 20383.2.patch, 1.4 KB (added by lancewillett, 8 years ago)

Updated patch to catch more punctuation; adds unit tests

  • src/wp-includes/canonical.php

     
    391391        // trailing /index.php
    392392        $redirect['path'] = preg_replace('|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path']);
    393393
    394         // Remove trailing spaces from the path
    395         $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] );
     394        // Remove trailing spaces and end punctuation from the path.
     395        $redirect['path'] = preg_replace( '#([^0-9a-zA-Z/]|%22|%7B|\)|%27|%E2%80%9C|%E2%80%9D|%20| )+$#', '', $redirect['path'] );
    396396
    397397        if ( !empty( $redirect['query'] ) ) {
    398398                // Remove trailing spaces from certain terminating query string args
  • tests/phpunit/tests/canonical/noRewrite.php

     
    5555                        array( '/?feed=rss2&p=1', '/?feed=rss2&p=1', 21841 ),
    5656                        array( '/?feed=rss&p=1', '/?feed=rss2&p=1', 24623 ),
    5757
     58                        // Trailing spaces and punctuation.
     59                        array( '/page/2/ ', '/page/2/' ),
     60                        array( '/page/2/%22', '/page/2/' ),
     61                        array( '/page/2/%27', '/page/2/' ),
     62                        array( '/page/2/%E2%80%9C', '/page/2/' ),
    5863                );
    5964        }
    6065}