Make WordPress Core

Changeset 61197


Ignore:
Timestamp:
11/10/2025 10:22:18 PM (11 months ago)
Author:
luisherranz
Message:

Interactivity API: Fatal error processing incorrect closed tags.

Fix for fatal errors caused by incorrect closing tags in HTML, such as </br>. In these cases, the get_attribute_names_with_prefix method of the WP_HTML_Tag_Processor returns null, and the Interactivity API was not handling this situation correctly.

Props hugosolar, jonsurrell, darerodz.
Fixes #63891.

Location:
trunk
Files:
2 edited

Legend:

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

    r61020 r61197  
    521521                                }
    522522                        } else {
    523                                 if ( 0 !== count( $p->get_attribute_names_with_prefix( 'data-wp-each-child' ) ) ) {
     523                                $each_child_attrs = $p->get_attribute_names_with_prefix( 'data-wp-each-child' );
     524                                if ( null === $each_child_attrs ) {
     525                                        continue;
     526                                }
     527
     528                                if ( 0 !== count( $each_child_attrs ) ) {
    524529                                        /*
    525530                                         * If the tag has a `data-wp-each-child` directive, jump to its closer
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php

    r61020 r61197  
    12581258
    12591259        /**
     1260         * Tests that the `process_directives` handles self-closing BR tags without
     1261         * causing fatal errors and processes directives correctly.
     1262         *
     1263         * @ticket 63891
     1264         * @covers ::process_directives
     1265         */
     1266        public function test_process_directives_handles_br_self_closing_tags_with_invalid_closers() {
     1267                $this->interactivity->state(
     1268                        'myPlugin',
     1269                        array(
     1270                                'id' => 'some-id',
     1271                        )
     1272                );
     1273
     1274                $html = '</br><div data-wp-bind--id="myPlugin::state.id">Content</div>';
     1275
     1276                $processed_html = $this->interactivity->process_directives( $html );
     1277
     1278                $p = new WP_HTML_Tag_Processor( $processed_html );
     1279                $p->next_tag( 'div' );
     1280
     1281                $this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
     1282        }
     1283
     1284        /**
    12601285         * Tests that the `process_directives` process the HTML outside a SVG tag.
    12611286         *
Note: See TracChangeset for help on using the changeset viewer.