Make WordPress Core

Ticket #37304: 37304.4.patch

File 37304.4.patch, 4.6 KB (added by enrico.sorcinelli, 7 years ago)

The updated patch for current trunk

  • src/wp-includes/shortcodes.php

     
    487487 * @return string The shortcode attribute regular expression
    488488 */
    489489function get_shortcode_atts_regex() {
    490         return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
     490        return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|\'([^\']*)\'(?:\s|$)|(\S+)(?:\s|$)/';
    491491}
    492492
    493493/**
     
    519519                                $atts[strtolower($m[5])] = stripcslashes($m[6]);
    520520                        elseif (isset($m[7]) && strlen($m[7]))
    521521                                $atts[] = stripcslashes($m[7]);
    522                         elseif (isset($m[8]))
     522                        elseif (isset($m[8]) && strlen($m[8]))
    523523                                $atts[] = stripcslashes($m[8]);
     524                        elseif (isset($m[9]))
     525                                $atts[] = stripcslashes($m[9]);
    524526                }
    525527
    526528                // Reject any unclosed HTML elements
  • src/wp-includes/js/shortcode.js

     
    134134                        // 5. An attribute name, that corresponds to...
    135135                        // 6. an unquoted value.
    136136                        // 7. A numeric attribute in double quotes.
    137                         // 8. An unquoted numeric attribute.
    138                         pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g;
     137                        // 8. A numeric attribute in single quotes.
     138                        // 9. An unquoted numeric attribute.
     139                        pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
    139140
    140141                        // Map zero-width spaces to actual spaces.
    141142                        text = text.replace( /[\u00a0\u200b]/g, ' ' );
     
    152153                                        numeric.push( match[7] );
    153154                                } else if ( match[8] ) {
    154155                                        numeric.push( match[8] );
     156                                } else if ( match[9] ) {
     157                                        numeric.push( match[9] );
    155158                                }
    156159                        }
    157160
  • tests/phpunit/tests/shortcode.php

     
    840840                );
    841841                return wp_json_encode( $arr );
    842842        }
     843
     844        /**
     845         * @ticket 37304
     846         *
     847         * Test 'value' syntax for empty attributes
     848         */
     849        function test_empty_single_quote_attribute() {
     850                $out = do_shortcode( '[test-shortcode-tag a="foo" b=\'bar\' c=baz foo \'bar\' "baz" ]test empty atts[/test-shortcode-tag]' );
     851                $this->assertEquals( array( 'a' => 'foo', 'b' => 'bar', 'c' => 'baz', 0 => 'foo', 1 => 'bar', 2 => 'baz' ), $this->atts );
     852        }
     853
     854        /**
     855         * @ticket 37304
     856         */
     857        function test_positional_atts_single_quotes() {
     858                $out = do_shortcode( "[test-shortcode-tag 'something in quotes' 'something else']" );
     859                $this->assertEquals( '', $out );
     860                $this->assertEquals( array( 0 => 'something in quotes', 1 => 'something else' ), $this->atts );
     861                $this->assertEquals( 'test-shortcode-tag', $this->tagname );
     862        }
     863
     864        /**
     865         * @ticket 37304
     866         */
     867        function test_positional_atts_mixed_quotes() {
     868                $out = do_shortcode( "[test-shortcode-tag 'something in quotes' \"something else\" 123 foo bar='baz' example=\"test\" ]" );
     869                $this->assertEquals( '', $out );
     870                $this->assertEquals( array( 0 => 'something in quotes', 1 => 'something else', 2 => '123', 3 => 'foo', 'bar' => 'baz', 'example' => 'test'), $this->atts );
     871                $this->assertEquals( 'test-shortcode-tag', $this->tagname );
     872        }
    843873}
  • tests/qunit/wp-includes/js/shortcode.js

     
    196196
    197197        deepEqual( wp.shortcode.attrs('foo not="a blocker" bar baz'), expected, 'attr parsed numeric attributes');
    198198    });
     199
     200        test( 'attrs() should return numeric attributes created with single, double, and no quotes', function() {
     201                var expected = {
     202                        'named': {}, 'numeric' : ['foo', 'bar', 'baz']
     203                };
     204
     205                deepEqual( wp.shortcode.attrs('foo "bar" \'baz\''), expected, 'attr parsed numeric attributes');
     206        });
     207       
     208        test( 'attrs() should return mixed attributes created with single, double, and no quotes', function() {
     209                var expected = {
     210                        'named': { a: 'foo', b: 'bar', c: 'baz' }, 'numeric' : ['foo', 'bar', 'baz']
     211                };
     212
     213                deepEqual( wp.shortcode.attrs('a="foo" b=\'bar\' c=baz foo "bar" \'baz\''), expected, 'attr parsed numeric attributes');
     214        });
    199215});