Make WordPress Core


Ignore:
Timestamp:
05/21/2020 04:52:33 AM (4 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.