Make WordPress Core


Ignore:
Timestamp:
07/22/2015 05:14:50 AM (9 years ago)
Author:
pento
Message:

Shortcodes: Improve the reliablity of shortcodes inside HTML tags.

Props miqrogroove.

See #15694.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/kses.php

    r32860 r33359  
    465465        );
    466466    }
     467
     468    /**
     469     * Test new function wp_kses_hair_parse().
     470     *
     471     * @dataProvider data_hair_parse
     472     */
     473    function test_hair_parse( $input, $output ) {
     474        return $this->assertEquals( $output, wp_kses_hair_parse( $input ) );
     475    }
     476
     477    function data_hair_parse() {
     478        return array(
     479            array(
     480                'title="hello" href="#" id="my_id" ',
     481                array( 'title="hello" ', 'href="#" ', 'id="my_id" ' ),
     482            ),
     483            array(
     484                '[shortcode attr="value"] href="http://www.google.com/"title="moo"disabled',
     485                array( '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled' ),
     486            ),
     487            array(
     488                '',
     489                array(),
     490            ),
     491            array(
     492                'a',
     493                array( 'a' ),
     494            ),
     495            array(
     496                'title="hello"disabled href=# id=\'my_id\'',
     497                array( 'title="hello"', 'disabled ', 'href=# ', "id='my_id'" ),
     498            ),
     499            array(
     500                '     ', // Calling function is expected to strip leading whitespace.
     501                false,
     502            ),
     503            array(
     504                'abcd=abcd"abcd"',
     505                false,
     506            ),
     507            array(
     508                "array[1]='z'z'z'z",
     509                false,
     510            ),
     511        );
     512    }
     513
     514    /**
     515     * Test new function wp_kses_attr_parse().
     516     *
     517     * @dataProvider data_attr_parse
     518     */
     519    function test_attr_parse( $input, $output ) {
     520        return $this->assertEquals( $output, wp_kses_attr_parse( $input ) );
     521    }
     522
     523    function data_attr_parse() {
     524        return array(
     525            array(
     526                '<a title="hello" href="#" id="my_id" >',
     527                array( '<a ', 'title="hello" ', 'href="#" ', 'id="my_id" ', '>' ),
     528            ),
     529            array(
     530                '<a [shortcode attr="value"] href="http://www.google.com/"title="moo"disabled>',
     531                array( '<a ', '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled', '>' ),
     532            ),
     533            array(
     534                '',
     535                false,
     536            ),
     537            array(
     538                'a',
     539                false,
     540            ),
     541            array(
     542                '<a>',
     543                array( '<a', '>' ),
     544            ),
     545            array(
     546                '<a%%&&**>',
     547                false,
     548            ),
     549            array(
     550                '<a title="hello"disabled href=# id=\'my_id\'>',
     551                array( '<a ', 'title="hello"', 'disabled ', 'href=# ', "id='my_id'", ">" ),
     552            ),
     553            array(
     554                '<a     >',
     555                array( '<a     ', '>' ),
     556            ),
     557            array(
     558                '<a abcd=abcd"abcd">',
     559                false,
     560            ),
     561            array(
     562                "<a array[1]='z'z'z'z>",
     563                false,
     564            ),
     565            array(
     566                '<img title="hello" src="#" id="my_id" />',
     567                array( '<img ', 'title="hello" ', 'src="#" ', 'id="my_id"', ' />' ),
     568            ),
     569        );
     570    }
     571
     572    /**
     573     * Test new function wp_kses_one_attr().
     574     *
     575     * @dataProvider data_one_attr
     576     */
     577    function test_one_attr( $element, $input, $output ) {
     578        return $this->assertEquals( $output, wp_kses_one_attr( $input, $element ) );
     579    }
     580
     581    function data_one_attr() {
     582        return array(
     583            array(
     584                'a',
     585                ' title="hello" ',
     586                ' title="hello" ',
     587            ),
     588            array(
     589                'a',
     590                'title  =  "hello"',
     591                'title="hello"',
     592            ),
     593            array(
     594                'a',
     595                "title='hello'",
     596                "title='hello'",
     597            ),
     598            array(
     599                'a',
     600                'title=hello',
     601                'title="hello"',
     602            ),
     603            array(
     604                'a',
     605                'href="javascript:alert(1)"',
     606                'href="alert(1)"',
     607            ),
     608            array(
     609                'a',
     610                'style ="style "',
     611                'style="style"',
     612            ),
     613            array(
     614                'a',
     615                'style="style "',
     616                'style="style"',
     617            ),
     618            array(
     619                'a',
     620                'style ="style ="',
     621                '',
     622            ),
     623            array(
     624                'img',
     625                'src="mypic.jpg"',
     626                'src="mypic.jpg"',
     627            ),
     628            array(
     629                'img',
     630                'onerror=alert(1)',
     631                '',
     632            ),
     633            array(
     634                'img',
     635                'title=>',
     636                'title="&gt;"',
     637            ),
     638            array(
     639                'img',
     640                'title="&garbage";"',
     641                'title="&amp;garbage&quot;;"',
     642            ),
     643        );
     644    }
    467645}
Note: See TracChangeset for help on using the changeset viewer.