Make WordPress Core


Ignore:
Timestamp:
07/22/2024 10:22:03 PM (12 months ago)
Author:
dmsnell
Message:

HTML API: Add missing tags in IN BODY insertion mode to HTML Processor.

As part of work to add more spec support to the HTML API, this patch adds
support for the remaining missing tags in the IN BODY insertion mode. Not
all of the added tags are supported, because in some cases they reset the
insertion mode and are reprocessed where they will be rejected.

This patch also improves the support of get_modifiable_text(), removing
a leading newline inside a LISTING, PRE, or TEXTAREA element.

Developed in https://github.com/WordPress/wordpress-develop/pull/6972
Discussed in https://core.trac.wordpress.org/ticket/61576

Props dmsnell, jonsurrell, westonruter.
See #61576.

File:
1 edited

Legend:

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

    r58713 r58779  
    407407
    408408    /**
    409      * Ensures that support isn't accidentally partially added for the closing BR tag `</br>`.
    410      *
    411      * This tag closer has special rules and support shouldn't be added without implementing full support.
     409     * Ensures that closing `</br>` tags are appropriately treated as opening tags with no attributes.
    412410     *
    413411     * > An end tag whose tag name is "br"
     
    416414     * >   tag token that it actually is.
    417415     *
    418      * When this handling is implemented, this test should be removed. It's not incorporated
    419      * into the existing unsupported tag behavior test because the opening tag is supported;
    420      * only the closing tag isn't.
    421      *
    422416     * @covers WP_HTML_Processor::step_in_body
    423417     *
     
    425419     */
    426420    public function test_br_end_tag_unsupported() {
    427         $processor = WP_HTML_Processor::create_fragment( '</br>' );
    428 
    429         $this->assertFalse( $processor->next_tag(), 'Found a BR tag that should not be handled.' );
    430         $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $processor->get_last_error() );
     421        $processor = WP_HTML_Processor::create_fragment( '</br id="an-opener" html>' );
     422
     423        $this->assertTrue( $processor->next_tag(), 'Failed to find the expected opening BR tag.' );
     424        $this->assertFalse( $processor->is_tag_closer(), 'Should have treated the tag as an opening tag.' );
     425        $this->assertNull( $processor->get_attribute_names_with_prefix( '' ), 'Should have ignored any attributes on the tag.' );
    431426    }
    432427}
Note: See TracChangeset for help on using the changeset viewer.