Make WordPress Core


Ignore:
Timestamp:
07/23/2015 05:00:44 AM (10 years ago)
Author:
pento
Message:

Shortcodes: Improve the reliablity of shortcodes inside HTML tags.

Merge of [33359] to the 3.9 branch.

Props miqrogroove.

See #15694.

File:
1 edited

Legend:

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

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