Make WordPress Core


Ignore:
Timestamp:
07/23/2015 04:36:55 AM (11 years ago)
Author:
pento
Message:

Shortcodes: Improve the reliablity of shortcodes inside HTML tags.

Merge of [33359] to the 4.1 branch.

Props miqrogroove.

See #15694.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/tests/phpunit/tests/kses.php

    r28942 r33380  
    412412                );
    413413        }
     414
     415        /**
     416         * Test new function wp_kses_hair_parse().
     417         *
     418         * @dataProvider data_hair_parse
     419         */
     420        function test_hair_parse( $input, $output ) {
     421                return $this->assertEquals( $output, wp_kses_hair_parse( $input ) );
     422        }
     423
     424        function data_hair_parse() {
     425                return array(
     426                        array(
     427                                'title="hello" href="#" id="my_id" ',
     428                                array( 'title="hello" ', 'href="#" ', 'id="my_id" ' ),
     429                        ),
     430                        array(
     431                                '[shortcode attr="value"] href="http://www.google.com/"title="moo"disabled',
     432                                array( '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled' ),
     433                        ),
     434                        array(
     435                                '',
     436                                array(),
     437                        ),
     438                        array(
     439                                'a',
     440                                array( 'a' ),
     441                        ),
     442                        array(
     443                                'title="hello"disabled href=# id=\'my_id\'',
     444                                array( 'title="hello"', 'disabled ', 'href=# ', "id='my_id'" ),
     445                        ),
     446                        array(
     447                                '     ', // Calling function is expected to strip leading whitespace.
     448                                false,
     449                        ),
     450                        array(
     451                                'abcd=abcd"abcd"',
     452                                false,
     453                        ),
     454                        array(
     455                                "array[1]='z'z'z'z",
     456                                false,
     457                        ),
     458                );
     459        }
     460
     461        /**
     462         * Test new function wp_kses_attr_parse().
     463         *
     464         * @dataProvider data_attr_parse
     465         */
     466        function test_attr_parse( $input, $output ) {
     467                return $this->assertEquals( $output, wp_kses_attr_parse( $input ) );
     468        }
     469
     470        function data_attr_parse() {
     471                return array(
     472                        array(
     473                                '<a title="hello" href="#" id="my_id" >',
     474                                array( '<a ', 'title="hello" ', 'href="#" ', 'id="my_id" ', '>' ),
     475                        ),
     476                        array(
     477                                '<a [shortcode attr="value"] href="http://www.google.com/"title="moo"disabled>',
     478                                array( '<a ', '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled', '>' ),
     479                        ),
     480                        array(
     481                                '',
     482                                false,
     483                        ),
     484                        array(
     485                                'a',
     486                                false,
     487                        ),
     488                        array(
     489                                '<a>',
     490                                array( '<a', '>' ),
     491                        ),
     492                        array(
     493                                '<a%%&&**>',
     494                                false,
     495                        ),
     496                        array(
     497                                '<a title="hello"disabled href=# id=\'my_id\'>',
     498                                array( '<a ', 'title="hello"', 'disabled ', 'href=# ', "id='my_id'", ">" ),
     499                        ),
     500                        array(
     501                                '<a     >',
     502                                array( '<a     ', '>' ),
     503                        ),
     504                        array(
     505                                '<a abcd=abcd"abcd">',
     506                                false,
     507                        ),
     508                        array(
     509                                "<a array[1]='z'z'z'z>",
     510                                false,
     511                        ),
     512                        array(
     513                                '<img title="hello" src="#" id="my_id" />',
     514                                array( '<img ', 'title="hello" ', 'src="#" ', 'id="my_id"', ' />' ),
     515                        ),
     516                );
     517        }
     518
     519        /**
     520         * Test new function wp_kses_one_attr().
     521         *
     522         * @dataProvider data_one_attr
     523         */
     524        function test_one_attr( $element, $input, $output ) {
     525                return $this->assertEquals( $output, wp_kses_one_attr( $input, $element ) );
     526        }
     527
     528        function data_one_attr() {
     529                return array(
     530                        array(
     531                                'a',
     532                                ' title="hello" ',
     533                                ' title="hello" ',
     534                        ),
     535                        array(
     536                                'a',
     537                                'title  =  "hello"',
     538                                'title="hello"',
     539                        ),
     540                        array(
     541                                'a',
     542                                "title='hello'",
     543                                "title='hello'",
     544                        ),
     545                        array(
     546                                'a',
     547                                'title=hello',
     548                                'title="hello"',
     549                        ),
     550                        array(
     551                                'a',
     552                                'href="javascript:alert(1)"',
     553                                'href="alert(1)"',
     554                        ),
     555                        array(
     556                                'a',
     557                                'style ="style "',
     558                                'style="style"',
     559                        ),
     560                        array(
     561                                'a',
     562                                'style="style "',
     563                                'style="style"',
     564                        ),
     565                        array(
     566                                'a',
     567                                'style ="style ="',
     568                                '',
     569                        ),
     570                        array(
     571                                'img',
     572                                'src="mypic.jpg"',
     573                                'src="mypic.jpg"',
     574                        ),
     575                        array(
     576                                'img',
     577                                'onerror=alert(1)',
     578                                '',
     579                        ),
     580                        array(
     581                                'img',
     582                                'title=>',
     583                                'title="&gt;"',
     584                        ),
     585                        array(
     586                                'img',
     587                                'title="&garbage";"',
     588                                'title="&amp;garbage&quot;;"',
     589                        ),
     590                );
     591        }
    414592}
Note: See TracChangeset for help on using the changeset viewer.