Make WordPress Core


Ignore:
Timestamp:
09/13/2023 12:53:32 PM (20 months ago)
Author:
Bernhard Reiter
Message:

HTML API: Skip over contents of RAWTEXT elements such as STYLE.

When encountering elements that imply switching into the RAWTEXT parsing state,
the Tag Processor should skip processing until exiting the RAWTEXT state.

In this patch the Tag Processor does just that, except for the case of the
deprecated XMP element which implies further and more complicated rules.

There's an implicit assumption that the SCRIPT ENABLED flag in HTML parsing
is enabled so that the contents of NOSCRIPT can be skipped. Otherwise, it would
be required to parse the contents of that tag.

Props dmsnell.
Merges [56563] to the 6.3 branch.
Fixes #59292.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r56133 r56564  
    18731873
    18741874    /**
     1875     * @ticket 59292
     1876     *
     1877     * @covers WP_HTML_Tag_Processor::next_tag
     1878     *
     1879     * @dataProvider data_next_tag_ignores_contents_of_rawtext_tags
     1880     *
     1881     * @param string $rawtext_element_then_target_node HTML starting with a RAWTEXT-specifying element such as STYLE,
     1882     *                                                 then an element afterward containing the "target" attribute.
     1883     */
     1884    public function test_next_tag_ignores_contents_of_rawtext_tags( $rawtext_element_then_target_node ) {
     1885        $processor = new WP_HTML_Tag_Processor( $rawtext_element_then_target_node );
     1886        $processor->next_tag();
     1887
     1888        $processor->next_tag();
     1889        $this->assertNotNull(
     1890            $processor->get_attribute( 'target' ),
     1891            "Expected to find element with target attribute but found {$processor->get_tag()} instead."
     1892        );
     1893    }
     1894
     1895    /**
     1896     * Data provider.
     1897     *
     1898     * @return array[].
     1899     */
     1900    public function data_next_tag_ignores_contents_of_rawtext_tags() {
     1901        return array(
     1902            'IFRAME'           => array( '<iframe><section>Inside</section></iframe><section target>' ),
     1903            'NOEMBED'          => array( '<noembed><p></p></noembed><div target>' ),
     1904            'NOFRAMES'         => array( '<noframes><p>Check the rules here.</p></noframes><div target>' ),
     1905            'NOSCRIPT'         => array( '<noscript><span>This assumes that scripting mode is enabled.</span></noscript><p target>' ),
     1906            'STYLE'            => array( '<style>* { margin: 0 }</style><div target>' ),
     1907            'STYLE hiding DIV' => array( '<style>li::before { content: "<div non-target>" }</style><div target>' ),
     1908        );
     1909    }
     1910
     1911    /**
    18751912     * Ensures that the invalid comment closing syntax "--!>" properly closes a comment.
    18761913     *
Note: See TracChangeset for help on using the changeset viewer.