Make WordPress Core

Ticket #34191: 34191.2.patch

File 34191.2.patch, 2.6 KB (added by johnbillion, 10 years ago)
  • src/wp-includes/js/shortcode.js

     
    135135                        // 6. an unquoted value.
    136136                        // 7. A numeric attribute in double quotes.
    137137                        // 8. An unquoted numeric attribute.
    138                         pattern = /(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g;
     138                        pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g;
    139139
    140140                        // Map zero-width spaces to actual spaces.
    141141                        text = text.replace( /[\u00a0\u200b]/g, ' ' );
  • tests/phpunit/tests/shortcode.php

     
    632632                require_once( DIR_TESTDATA . '/formatting/whole-posts.php' );
    633633                return data_whole_posts();
    634634        }
     635
     636        function test_php_and_js_shortcode_attribute_regexes_match() {
     637
     638                $file = file_get_contents( ABSPATH . WPINC . '/js/shortcode.js' );
     639                $matched = preg_match( '|\s+pattern = (\/.+\/)g;|', $file, $matches );
     640                $php = get_shortcode_atts_regex();
     641
     642                $this->assertSame( 1, $matched );
     643
     644                $js = str_replace( "\'", "'", $matches[1] );
     645                $this->assertSame( $php, $js );
     646
     647        }
     648
    635649}
  • src/wp-includes/shortcodes.php

     
    451451}
    452452
    453453/**
     454 * Retrieve the shortcode attributes regex.
     455 *
     456 * @since 4.4.0
     457 *
     458 * @return string The shortcode attribute regular expression
     459 */
     460function get_shortcode_atts_regex() {
     461        return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
     462}
     463
     464/**
    454465 * Retrieve all attributes from the shortcodes tag.
    455466 *
    456467 * The attributes list has the attribute name as the key and the value of the
     
    467478 */
    468479function shortcode_parse_atts($text) {
    469480        $atts = array();
    470         $pattern = '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
     481        $pattern = get_shortcode_atts_regex();
    471482        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
    472483        if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
    473484                foreach ($match as $m) {