Make WordPress Core

Changeset 47837


Ignore:
Timestamp:
05/21/2020 04:52:33 AM (6 years ago)
Author:
peterwilsoncc
Message:

KSES: Support the video element's playsinline attribute.

Allow users without the unfiltered_html capability to use the playsinline attribute when embedding videos.

Additionally this adds unit tests for passing the video element through kses.

Fixes #50167. See #29826.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/kses.php

    r47808 r47837  
    398398                'var'        => array(),
    399399                'video'      => array(
    400                         'autoplay' => true,
    401                         'controls' => true,
    402                         'height'   => true,
    403                         'loop'     => true,
    404                         'muted'    => true,
    405                         'poster'   => true,
    406                         'preload'  => true,
    407                         'src'      => true,
    408                         'width'    => true,
     400                        'autoplay'    => true,
     401                        'controls'    => true,
     402                        'height'      => true,
     403                        'loop'        => true,
     404                        'muted'       => true,
     405                        'playsinline' => true,
     406                        'poster'      => true,
     407                        'preload'     => true,
     408                        'src'         => true,
     409                        'width'       => true,
    409410                ),
    410411        );
  • trunk/tests/phpunit/tests/kses.php

    r47122 r47837  
    6262                        $this->assertEquals( $expect_string, wp_kses( $string, $allowedposttags ) );
    6363                }
     64        }
     65
     66        /**
     67         * Test video tag.
     68         *
     69         * @ticket 50167
     70         * @ticket 29826
     71         * @dataProvider data_wp_kses_video
     72         *
     73         * @param string $source   Source HTML.
     74         * @param string $context  Context to use for parsing source.
     75         * @param string $expected Expected output following KSES parsing.
     76         * @return void
     77         */
     78        function test_wp_kses_video( $source, $context, $expected ) {
     79                $actual = wp_kses( $source, $context );
     80                $this->assertSame( $expected, $actual );
     81        }
     82
     83        /**
     84         * Data provider for test_wp_kses_video
     85         *
     86         * @return array[] Array containing test data {
     87         *     @type string $source   Source HTML.
     88         *     @type string $context  Context to use for parsing source.
     89         *     @type string $expected Expected output following KSES parsing.
     90         * }
     91         */
     92        function data_wp_kses_video() {
     93                return array(
     94                        // Set 0: Valid post object params in post context.
     95                        array(
     96                                '<video src="movie.mov" autoplay controls height=9 loop muted poster="still.gif" playsinline preload width=16 />',
     97                                'post',
     98                                '<video src="movie.mov" autoplay controls height="9" loop muted poster="still.gif" playsinline preload width="16" />',
     99                        ),
     100                        // Set 1: Valid post object params in data context.
     101                        array(
     102                                '<video src="movie.mov" autoplay controls height=9 loop muted poster="still.gif" playsinline preload width=16 />',
     103                                'data',
     104                                '',
     105                        ),
     106                        // Set 2: Disallowed urls in post context.
     107                        array(
     108                                '<video src="bad://w.org/movie.mov" poster="bad://w.org/movie.jpg" />',
     109                                'post',
     110                                '<video src="//w.org/movie.mov" poster="//w.org/movie.jpg" />',
     111                        ),
     112                        // Set 3: Disallowed attributes in post context.
     113                        array(
     114                                '<video onload="alert(1);" src="https://videos.files.wordpress.com/DZEMDKxc/video-0f9c363010.mp4" />',
     115                                'post',
     116                                '<video src="https://videos.files.wordpress.com/DZEMDKxc/video-0f9c363010.mp4" />',
     117                        ),
     118                );
    64119        }
    65120
Note: See TracChangeset for help on using the changeset viewer.