Make WordPress Core


Ignore:
Timestamp:
03/09/2017 08:04:17 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Canonical: Strip trailing punctuation from permalinks.

Props joostdevalk, lancewillett, SergeyBiryukov.
Fixes #20383.

File:
1 edited

Legend:

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

    r38216 r40256  
    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    $punctuation_pattern = implode( '|', array_map( 'preg_quote', array(
     395        ' ', '%20',       // space
     396        '!', '%21',       // exclamation mark
     397        '"', '%22',       // double quote
     398        "'", '%27',       // single quote
     399        '(', '%28',       // opening bracket
     400        ')', '%29',       // closing bracket
     401        ',', '%2C',       // comma
     402        '.', '%2E',       // period
     403        ';', '%3B',       // semicolon
     404        '{', '%7B',       // opening curly bracket
     405        '}', '%7D',       // closing curly bracket
     406        '“', '%E2%80%9C', // opening curly quote
     407        '”', '%E2%80%9D', // closing curly quote
     408    ) ) );
     409
     410    // Remove trailing spaces and end punctuation from the path.
     411    $redirect['path'] = preg_replace( "#($punctuation_pattern)+$#", '', $redirect['path'] );
    396412
    397413    if ( !empty( $redirect['query'] ) ) {
    398         // Remove trailing spaces from certain terminating query string args
    399         $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] );
     414        // Remove trailing spaces and end punctuation from certain terminating query string args.
     415        $redirect['query'] = preg_replace( "#((p|page_id|cat|tag)=[^&]*?)($punctuation_pattern)+$#", '$1', $redirect['query'] );
    400416
    401417        // Clean up empty query strings
Note: See TracChangeset for help on using the changeset viewer.