Make WordPress Core


Ignore:
Timestamp:
01/23/2025 06:35:15 PM (21 months ago)
Author:
jorbin
Message:

HTML API: Expect closer on foreign content void lookalike elements.

Ensure that expects_closer returns false on tags that look like void HTML tags, but are actually not void tags in foreign content.

Reviewed by westonruter, jorbin.
Merges [59392] to the 6.7 branch.

Props jonsurrell, bernhard-reiter.
Fixes #62363.

Location:
branches/6.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.7

  • branches/6.7/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r59535 r59694  
    563563
    564564        /**
     565         * Ensures that expects_closer works for void-like elements in foreign content.
     566         *
     567         * For example, `<svg><input>text` creates an `svg:input` that contains a text node.
     568         * This input should not be treated as a void tag and _should_ expect a close tag.
     569         *
     570         * @dataProvider data_void_tags
     571         *
     572         * @ticket 62363
     573         */
     574        public function test_expects_closer_foreign_content_not_void( string $void_tag ) {
     575                $processor = WP_HTML_Processor::create_fragment( "<svg><{$void_tag}>" );
     576
     577                $this->assertTrue( $processor->next_tag( $void_tag ) );
     578
     579                // Some void-like tags will close the SVG element and be HTML tags.
     580                if ( $processor->get_namespace() === 'svg' ) {
     581                        $this->assertSame( array( 'HTML', 'BODY', 'SVG', $void_tag ), $processor->get_breadcrumbs() );
     582                        $this->assertTrue( $processor->expects_closer() );
     583                } else {
     584                        $this->assertSame( array( 'HTML', 'BODY', $void_tag ), $processor->get_breadcrumbs() );
     585                        $this->assertFalse( $processor->expects_closer() );
     586                }
     587        }
     588
     589        /**
    565590         * Ensures that self-closing foreign SCRIPT elements are properly found.
    566591         *
Note: See TracChangeset for help on using the changeset viewer.