Make WordPress Core


Ignore:
Timestamp:
07/23/2015 05:14:09 AM (11 years ago)
Author:
pento
Message:

Shortcodes: Improve the reliablity of shortcodes inside HTML tags.

Merge of [33359] to the 3.7 branch.

Props miqrogroove.

See #15694.

File:
1 edited

Legend:

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

    r25002 r33389  
    360360        $this->assertEquals( $allowedtags, wp_kses_allowed_html( 'data' ) );
    361361    }
     362
     363    /**
     364     * Test new function wp_kses_hair_parse().
     365     *
     366     * @dataProvider data_hair_parse
     367     */
     368    function test_hair_parse( $input, $output ) {
     369        return $this->assertEquals( $output, wp_kses_hair_parse( $input ) );
     370    }
     371
     372    function data_hair_parse() {
     373        return array(
     374            array(
     375                'title="hello" href="#" id="my_id" ',
     376                array( 'title="hello" ', 'href="#" ', 'id="my_id" ' ),
     377            ),
     378            array(
     379                '[shortcode attr="value"] href="http://www.google.com/"title="moo"disabled',
     380                array( '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled' ),
     381            ),
     382            array(
     383                '',
     384                array(),
     385            ),
     386            array(
     387                'a',
     388                array( 'a' ),
     389            ),
     390            array(
     391                'title="hello"disabled href=# id=\'my_id\'',
     392                array( 'title="hello"', 'disabled ', 'href=# ', "id='my_id'" ),
     393            ),
     394            array(
     395                '     ', // Calling function is expected to strip leading whitespace.
     396                false,
     397            ),
     398            array(
     399                'abcd=abcd"abcd"',
     400                false,
     401            ),
     402            array(
     403                "array[1]='z'z'z'z",
     404                false,
     405            ),
     406        );
     407    }
     408
     409    /**
     410     * Test new function wp_kses_attr_parse().
     411     *
     412     * @dataProvider data_attr_parse
     413     */
     414    function test_attr_parse( $input, $output ) {
     415        return $this->assertEquals( $output, wp_kses_attr_parse( $input ) );
     416    }
     417
     418    function data_attr_parse() {
     419        return array(
     420            array(
     421                '<a title="hello" href="#" id="my_id" >',
     422                array( '<a ', 'title="hello" ', 'href="#" ', 'id="my_id" ', '>' ),
     423            ),
     424            array(
     425                '<a [shortcode attr="value"] href="http://www.google.com/"title="moo"disabled>',
     426                array( '<a ', '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled', '>' ),
     427            ),
     428            array(
     429                '',
     430                false,
     431            ),
     432            array(
     433                'a',
     434                false,
     435            ),
     436            array(
     437                '<a>',
     438                array( '<a', '>' ),
     439            ),
     440            array(
     441                '<a%%&&**>',
     442                false,
     443            ),
     444            array(
     445                '<a title="hello"disabled href=# id=\'my_id\'>',
     446                array( '<a ', 'title="hello"', 'disabled ', 'href=# ', "id='my_id'", ">" ),
     447            ),
     448            array(
     449                '<a     >',
     450                array( '<a     ', '>' ),
     451            ),
     452            array(
     453                '<a abcd=abcd"abcd">',
     454                false,
     455            ),
     456            array(
     457                "<a array[1]='z'z'z'z>",
     458                false,
     459            ),
     460            array(
     461                '<img title="hello" src="#" id="my_id" />',
     462                array( '<img ', 'title="hello" ', 'src="#" ', 'id="my_id"', ' />' ),
     463            ),
     464        );
     465    }
     466
     467    /**
     468     * Test new function wp_kses_one_attr().
     469     *
     470     * @dataProvider data_one_attr
     471     */
     472    function test_one_attr( $element, $input, $output ) {
     473        return $this->assertEquals( $output, wp_kses_one_attr( $input, $element ) );
     474    }
     475
     476    function data_one_attr() {
     477        return array(
     478            array(
     479                'a',
     480                ' title="hello" ',
     481                ' title="hello" ',
     482            ),
     483            array(
     484                'a',
     485                'title  =  "hello"',
     486                'title="hello"',
     487            ),
     488            array(
     489                'a',
     490                "title='hello'",
     491                "title='hello'",
     492            ),
     493            array(
     494                'a',
     495                'title=hello',
     496                'title="hello"',
     497            ),
     498            array(
     499                'a',
     500                'href="javascript:alert(1)"',
     501                'href="alert(1)"',
     502            ),
     503            array(
     504                'a',
     505                'style ="style "',
     506                'style="style"',
     507            ),
     508            array(
     509                'a',
     510                'style="style "',
     511                'style="style"',
     512            ),
     513            array(
     514                'a',
     515                'style ="style ="',
     516                '',
     517            ),
     518            array(
     519                'img',
     520                'src="mypic.jpg"',
     521                'src="mypic.jpg"',
     522            ),
     523            array(
     524                'img',
     525                'onerror=alert(1)',
     526                '',
     527            ),
     528            array(
     529                'img',
     530                'title=>',
     531                'title="&gt;"',
     532            ),
     533            array(
     534                'img',
     535                'title="&garbage";"',
     536                'title="&amp;garbage&quot;;"',
     537            ),
     538        );
     539    }
    362540}
Note: See TracChangeset for help on using the changeset viewer.