Make WordPress Core

Changeset 59392 for trunk


Ignore:
Timestamp:
11/12/2024 12:56:37 PM (21 months ago)
Author:
Bernhard Reiter
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.

Props jonsurrell, bernhard-reiter.
Fixes #62363.

Location:
trunk
Files:
2 edited

Legend:

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

    r59391 r59392  
    822822                        'html' === $token_name ||
    823823                        // Void elements.
    824                         self::is_void( $token_name ) ||
     824                        ( 'html' === $token_namespace && self::is_void( $token_name ) ) ||
    825825                        // Special atomic elements.
    826826                        ( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) ||
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r59391 r59392  
    560560                $this->assertSame( 'MATH', $processor->get_tag() );
    561561                $this->assertTrue( $processor->expects_closer() );
     562        }
     563
     564        /**
     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                }
    562587        }
    563588
Note: See TracChangeset for help on using the changeset viewer.