Make WordPress Core

Ticket #27588: miqro-27588.2.patch

File miqro-27588.2.patch, 3.3 KB (added by miqrogroove, 9 years ago)

Filter docs added.

  • src/wp-includes/formatting.php

     
    7373                $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney );
    7474                $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
    7575
    76                 /*
    77                  * Regex for common whitespace characters.
    78                  *
    79                  * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
    80                  * This is designed to replace the PCRE \s sequence.  In #WP22692, that sequence
    81                  * was found to be unreliable due to random inclusion of the A0 byte.
    82                  */
    83                 $spaces = '[\r\n\t ]|\xC2\xA0| ';
     76                $spaces = wp_spaces_regexp();
    8477
    8578
    8679                // Pattern-based replacements of characters.
     
    361354        }
    362355
    363356        $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
     357        $spaces = wp_spaces_regexp();
    364358
    365359        $pattern =
    366360                  '/'
    367361                . '<p>'                              // Opening paragraph
    368                 . '\\s*+'                            // Optional leading whitespace
     362                . '(?:' . $spaces . ')*+'            // Optional leading whitespace
    369363                . '('                                // 1: The shortcode
    370364                .     '\\['                          // Opening bracket
    371365                .     "($tagregexp)"                 // 2: Shortcode name
     
    390384                .         ')?'
    391385                .     ')'
    392386                . ')'
    393                 . '\\s*+'                            // optional trailing whitespace
     387                . '(?:' . $spaces . ')*+'            // optional trailing whitespace
    394388                . '<\\/p>'                           // closing paragraph
    395389                . '/s';
    396390
     
    38603854        static $spaces;
    38613855
    38623856        if ( empty( $spaces ) ) {
     3857                /**
     3858                 * Regexp for common whitespace characters.
     3859                 *
     3860                 * This string is substituted for the \s sequence as needed in regular expressions.
     3861                 * For websites not written in English, different characters may represent whitespace.
     3862                 * For websites not encoded in UTF-8, the 0xC2 0xA0 sequence may not be in use.
     3863                 *
     3864                 * @since 4.0.0
     3865                 *
     3866                 * @param string $spaces
     3867                 */
    38633868                $spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0|&nbsp;' );
    38643869        }
    38653870
    38663871        return $spaces;
    3867 }
    3868  No newline at end of file
     3872}
  • tests/phpunit/tests/shortcode.php

     
    373373                remove_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts2' ), 10, 3 );
    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}