Make WordPress Core

Ticket #34406: 34406.3.diff

File 34406.3.diff, 2.0 KB (added by travisnorthcutt, 9 years ago)

Updated patch with tests

  • src/wp-includes/kses.php

    diff --git src/wp-includes/kses.php src/wp-includes/kses.php
    index d34608b..668efd9 100644
    function wp_kses_hair($attr, $allowed_protocols) { 
    927927                switch ($mode) {
    928928                        case 0 : // attribute name, href for instance
    929929
    930                                 if ( preg_match('/^([-a-zA-Z:]+)/', $attr, $match ) ) {
     930                                if ( preg_match('/^([-_a-zA-Z0-9:]+)/', $attr, $match ) ) {
    931931                                        $attrname = $match[1];
    932932                                        $working = $mode = 1;
    933                                         $attr = preg_replace( '/^[-a-zA-Z:]+/', '', $attr );
     933                                        $attr = preg_replace( '/^[-_a-zA-Z0-9:]+/', '', $attr );
    934934                                }
    935935
    936936                                break;
  • tests/phpunit/tests/kses.php

    diff --git tests/phpunit/tests/kses.php tests/phpunit/tests/kses.php
    index c4c1e8e..69153e5 100644
    EOF; 
    653653
    654654                $this->assertEquals( $input, wp_kses( $input, $allowedposttags ) );
    655655        }
     656
     657    /**
     658     * Test wp_kses_hair().
     659     *
     660     * @ticket 34406
     661     *
     662     * @dataProvider data_hair
     663     */
     664    function test_hair( $input, $output, $allowed ) {
     665        return $this->assertEquals( $output, wp_kses( $input, $allowed ) );
     666    }
     667
     668    function data_hair() {
     669
     670        global $allowedposttags;
     671        $allowedposttags['img']['data_at:2x'] = true;
     672
     673        return array(
     674            array(
     675                '<img src="" data_at:2x="" alt="blah" />',
     676                '<img src="" data_at:2x="" alt="blah" />',
     677                $allowedposttags,
     678            ),
     679            array(
     680                '<img src="" data_at:2x="" alt="blah" />',
     681                '<img src="" data_at:2x="" alt="blah" />',
     682                $allowedposttags,
     683            ),
     684            array(
     685                '<img src="" data&="" alt="blah" />',
     686                '<img src="" alt="blah" />',
     687                $allowedposttags,
     688            ),
     689            array(
     690                '<img src="" data%="" alt="blah" />',
     691                '<img src="" alt="blah" />',
     692                $allowedposttags,
     693            ),
     694        );
     695    }
    656696}