Make WordPress Core

Changeset 56133


Ignore:
Timestamp:
07/04/2023 08:43:43 PM (11 months ago)
Author:
azaozz
Message:

HTML API: Fix a fatal error when processing malformed document with unclosed attribute.

Props: dlh, costdev, dmsnell.
Fixes: #58637.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r55734 r56133  
    547547
    548548            // Ensure that the tag closes before the end of the document.
     549            if ( $this->bytes_already_parsed >= strlen( $this->html ) ) {
     550                return false;
     551            }
     552
    549553            $tag_ends_at = strpos( $this->html, '>', $this->bytes_already_parsed );
    550554            if ( false === $tag_ends_at ) {
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r55706 r56133  
    20402040
    20412041    /**
     2042     * @ticket 58637
     2043     *
     2044     * @covers WP_HTML_Tag_Processor::next_tag
     2045     *
     2046     * @dataProvider data_incomplete_syntax_elements
     2047     *
     2048     * @param string $incomplete_html HTML text containing some kind of incomplete syntax.
     2049     */
     2050    public function test_returns_false_for_incomplete_syntax_elements( $incomplete_html ) {
     2051        $p = new WP_HTML_Tag_Processor( $incomplete_html );
     2052        $this->assertFalse( $p->next_tag() );
     2053    }
     2054
     2055    /**
     2056     * Data provider.
     2057     *
     2058     * @return array[]
     2059     */
     2060    public function data_incomplete_syntax_elements() {
     2061        return array(
     2062            'No tags'                              => array( 'this is nothing more than a text node' ),
     2063            'Incomplete tag name'                  => array( '<swit' ),
     2064            'Incomplete tag (no attributes)'       => array( '<div' ),
     2065            'Incomplete tag (attributes)'          => array( '<div inert title="test"' ),
     2066            'Incomplete attribute (unquoted)'      => array( '<button disabled' ),
     2067            'Incomplete attribute (single quoted)' => array( "<li class='just-another class" ),
     2068            'Incomplete attribute (double quoted)' => array( '<iframe src="https://www.example.com/embed/abcdef' ),
     2069            'Incomplete comment (normative)'       => array( '<!-- without end' ),
     2070            'Incomplete comment (missing --)'      => array( '<!-- without end --' ),
     2071            'Incomplete comment (--!)'             => array( '<!-- without end --!' ),
     2072            'Incomplete comment (bogus comment)'   => array( '</3 is not a tag' ),
     2073            'Incomplete DOCTYPE'                   => array( '<!DOCTYPE html' ),
     2074            'Partial DOCTYPE'                      => array( '<!DOCTY' ),
     2075            'Incomplete CDATA'                     => array( '<[CDATA[something inside of here needs to get out' ),
     2076            'Partial CDATA'                        => array( '<[CDA' ),
     2077            'Partially closed CDATA]'              => array( '<[CDATA[cannot escape]' ),
     2078            'Partially closed CDATA]>'             => array( '<[CDATA[cannot escape]>' ),
     2079        );
     2080    }
     2081
     2082    /**
    20422083     * @ticket 56299
    20432084     *
Note: See TracChangeset for help on using the changeset viewer.