Make WordPress Core


Ignore:
Timestamp:
11/10/2025 10:22:18 PM (12 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.