Make WordPress Core


Ignore:
Timestamp:
08/08/2024 04:13:25 PM (21 months ago)
Author:
dmsnell
Message:

HTML API: expect_closer() should report false for self-closing foreign elements.

Previously, WP_HTML_Processor::expects_closer() would report true for self-closing foreign elements when called without supplying a node in question, but it should have been reporting true just as it does for HTML elements.

This patch adds a test case demonstrating the issue and a bugfix.

The html5lib test runner was relying on the incorrect behavior, accidentally working. This is also corrected and the html5lib test now relies on the correct behavior of expects_closer().

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

Follow-up to [58868].

Props: dmsnell.
See #61576.

File:
1 edited

Legend:

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

    r58867 r58870  
    208208                    $tag_indent = $indent_level;
    209209
    210                     if ( 'html' !== $namespace ) {
    211                         if ( ! $processor->has_self_closing_flag() ) {
    212                             ++$indent_level;
    213                         }
    214                     } elseif ( ! WP_HTML_Processor::is_void( $tag_name ) ) {
     210                    if ( $processor->expects_closer() ) {
    215211                        ++$indent_level;
    216212                    }
     
    276272                    $modifiable_text = $processor->get_modifiable_text();
    277273                    if ( '' !== $modifiable_text ) {
    278                         $output .= str_repeat( $indent, $indent_level ) . "\"{$modifiable_text}\"\n";
     274                        $output .= str_repeat( $indent, $tag_indent + 1 ) . "\"{$modifiable_text}\"\n";
    279275                    }
    280276
     
    282278                        $output .= str_repeat( $indent, $indent_level ) . "content\n";
    283279                        ++$indent_level;
    284                     }
    285 
    286                     if ( ! $processor->is_void( $tag_name ) && ! $processor->expects_closer() ) {
    287                         --$indent_level;
    288280                    }
    289281
Note: See TracChangeset for help on using the changeset viewer.