Make WordPress Core

Ticket #32172: 32172.patch

File 32172.patch, 2.3 KB (added by tyxla, 10 years ago)

Adding support for single quote characters for positional shortcode attributes. Adding unit tests for attributes wrapped with single quotes.

  • src/wp-includes/shortcodes.php

     
    304304 */
    305305function shortcode_parse_atts($text) {
    306306        $atts = array();
    307         $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
     307        $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|\'([^\']*)\'(?:\s|$)|(\S+)(?:\s|$)/';
    308308        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
    309309        if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
    310310                foreach ($match as $m) {
     
    316316                                $atts[strtolower($m[5])] = stripcslashes($m[6]);
    317317                        elseif (isset($m[7]) && strlen($m[7]))
    318318                                $atts[] = stripcslashes($m[7]);
    319                         elseif (isset($m[8]))
     319                        elseif (isset($m[8]) && strlen($m[8]))
    320320                                $atts[] = stripcslashes($m[8]);
     321                        elseif (isset($m[9]))
     322                                $atts[] = stripcslashes($m[9]);
    321323                }
    322324        } else {
    323325                $atts = ltrim($text);
  • tests/phpunit/tests/shortcode.php

     
    188188                $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    189189        }
    190190
     191        /**
     192         * @ticket 32172
     193         */
     194        function test_positional_atts_single_quotes() {
     195                $out = do_shortcode("[test-shortcode-tag 'something in quotes' 'something else']");
     196                $this->assertEquals( '', $out );
     197                $this->assertEquals( array(0=>'something in quotes', 1=>'something else'), $this->atts );
     198                $this->assertEquals( 'test-shortcode-tag', $this->tagname );
     199        }
     200
     201        /**
     202         * @ticket 32172
     203         */
     204        function test_positional_atts_mixed_quotes() {
     205                $out = do_shortcode("[test-shortcode-tag 'something in quotes' \"something else\" 123 foo bar='baz' example=\"test\" ]");
     206                $this->assertEquals( '', $out );
     207                $this->assertEquals( array(0=>'something in quotes', 1=>'something else', 2 => '123', 3 => 'foo', 'bar' => 'baz', 'example' => 'test'), $this->atts );
     208                $this->assertEquals( 'test-shortcode-tag', $this->tagname );
     209        }
     210
    191211        function test_footag_default() {
    192212                $out = do_shortcode('[footag]');
    193213                $this->assertEquals('foo = ', $out);