Make WordPress Core

Changeset 28716


Ignore:
Timestamp:
06/10/2014 01:54:11 AM (12 years ago)
Author:
wonderboymusic
Message:

Ensure that shortcode_unautop() treats   like whitespace.
shortcode_unautop() and wptexturize() now use wp_spaces_regexp() instead of raw regex.

Adds unit tests.

Props miqrogroove.
See #27588.

Location:
trunk
Files:
2 edited

Legend:

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

    r28715 r28716  
    8383                $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
    8484
    85                 /*
    86                  * Regex for common whitespace characters.
    87                  *
    88                  * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
    89                  * This is designed to replace the PCRE \s sequence.  In #WP22692, that sequence
    90                  * was found to be unreliable due to random inclusion of the A0 byte.
    91                  */
    92                 $spaces = '[\r\n\t ]|\xC2\xA0| ';
     85                $spaces = wp_spaces_regexp();
    9386
    9487
    … …  
    371364
    372365        $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
     366        $spaces = wp_spaces_regexp();
    373367
    374368        $pattern =
    375369                  '/'
    376370                . '<p>'                              // Opening paragraph
    377                 . '\\s*+'                            // Optional leading whitespace
     371                . '(?:' . $spaces . ')*+'            // Optional leading whitespace
    378372                . '('                                // 1: The shortcode
    379373                .     '\\['                          // Opening bracket
    … …  
    400394                .     ')'
    401395                . ')'
    402                 . '\\s*+'                            // optional trailing whitespace
     396                . '(?:' . $spaces . ')*+'            // optional trailing whitespace
    403397                . '<\\/p>'                           // closing paragraph
    404398                . '/s';
    … …  
    38583852
    38593853        if ( empty( $spaces ) ) {
     3854                /**
     3855                 * Regexp for common whitespace characters.
     3856                 *
     3857                 * This string is substituted for the \s sequence as needed in regular expressions.
     3858                 * For websites not written in English, different characters may represent whitespace.
     3859                 * For websites not encoded in UTF-8, the 0xC2 0xA0 sequence may not be in use.
     3860                 *
     3861                 * @since 4.0.0
     3862                 *
     3863                 * @param string $spaces
     3864                 */
    38603865                $spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0|&nbsp;' );
    38613866        }
  • trunk/tests/phpunit/tests/shortcode.php

    r25002 r28716  
    374374        }
    375375
     376        /**
     377         * Check that shortcode_unautop() will always recognize spaces around shortcodes.
     378         *
     379         * @ticket 22692
     380         */
     381        function test_spaces_around_shortcodes() {
     382                $nbsp = "\xC2\xA0";
     383
     384                $input  = array();
     385
     386                $input[] = "<p>[gallery ids=\"37,15,11\"]</p>";
     387                $input[] = "<p> [gallery ids=\"37,15,11\"] </p>";
     388                $input[] = "<p> {$nbsp}[gallery ids=\"37,15,11\"] {$nbsp}</p>";
     389                $input[] = "<p> &nbsp;[gallery ids=\"37,15,11\"] &nbsp;</p>";
     390
     391                $output = "[gallery ids=\"37,15,11\"]";
     392
     393                foreach($input as $in) {
     394                        $this->assertEquals( $output, shortcode_unautop( $in ) );
     395                }
     396        }
    376397}
Note: See TracChangeset for help on using the changeset viewer.