Make WordPress Core


Ignore:
Timestamp:
01/19/2024 09:40:01 PM (11 months ago)
Author:
dmsnell
Message:

HTML API: Add support for BR, EMBED, & other tags.

Adds support for the following HTML elements to the HTML Processor:

  • AREA, BR, EMBED, KEYGEN, WBR
  • Only the opening BR tag is supported, as the invalid closer </br> involves more complicated rules, to be implemented later.

Previously, these elements were not supported and the HTML Processor
would bail when encountering them. With this patch it will proceed to
parse an HTML document when encountering those tags as long as other
normal conditions don't cause it to bail (such as complicated format
reconstruction rules).

Props jonsurrell, dmsnell
Fixes #60283

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

    r57314 r57316  
    393393        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' );
    394394    }
     395
     396    /**
     397     * Ensures that support isn't accidentally partially added for the closing BR tag `</br>`.
     398     *
     399     * This tag closer has special rules and support shouldn't be added without implementing full support.
     400     *
     401     * > An end tag whose tag name is "br"
     402     * >   Parse error. Drop the attributes from the token, and act as described in the next entry;
     403     * >   i.e. act as if this was a "br" start tag token with no attributes, rather than the end
     404     * >   tag token that it actually is.
     405     *
     406     * When this handling is implemented, this test should be removed. It's not incorporated
     407     * into the existing unsupported tag behavior test because the opening tag is supported;
     408     * only the closing tag isn't.
     409     *
     410     * @covers WP_HTML_Processor::step_in_body
     411     *
     412     * @ticket 60283
     413     */
     414    public function test_br_end_tag_unsupported() {
     415        $p = WP_HTML_Processor::create_fragment( '</br>' );
     416
     417        $this->assertFalse( $p->next_tag(), 'Found a BR tag that should not be handled.' );
     418        $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $p->get_last_error() );
     419    }
    395420}
Note: See TracChangeset for help on using the changeset viewer.