File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
src/wp-includes/interactivity-api
tests/phpunit/tests/interactivity-api Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -440,11 +440,8 @@ private function _process_directives( string $html ) {
440440 }
441441 } else {
442442 $ each_child_attrs = $ p ->get_attribute_names_with_prefix ( 'data-wp-each-child ' );
443- if ( ! is_countable ( $ each_child_attrs ) ) {
444- continue ;
445- }
446443
447- if ( 0 !== count ( $ each_child_attrs ) ) {
444+ if ( null !== $ each_child_attrs && 0 !== count ( $ each_child_attrs ) ) {
448445 /*
449446 * If the tag has a `data-wp-each-child` directive, jump to its closer
450447 * tag because those tags have already been processed.
Original file line number Diff line number Diff line change @@ -830,9 +830,37 @@ public static function data_html_with_unbalanced_tags() {
830830 'SPAN opener inside ' => array ( '<div data-wp-bind--id="myPlugin::state.id"><span>Inner content</div> ' ),
831831 'SPAN closer after ' => array ( '<div data-wp-bind--id="myPlugin::state.id">Inner content</div></span> ' ),
832832 'SPAN overlapping ' => array ( '<div data-wp-bind--id="myPlugin::state.id"><span>Inner content</div></span> ' ),
833+ 'BR self-closing ' => array ( '<div data-wp-bind--id="myPlugin::state.id">Content<br></br></div> ' ),
833834 );
834835 }
835836
837+ /**
838+ * Tests that the `process_directives` handles self-closing tags with invalid
839+ * closing tags without causing fatal errors.
840+ *
841+ * @covers ::process_directives
842+ *
843+ * @expectedIncorrectUsage WP_Interactivity_API::_process_directives
844+ */
845+ public function test_process_directives_handles_self_closing_tags_with_invalid_closers () {
846+ $ this ->interactivity ->state (
847+ 'myPlugin ' ,
848+ array (
849+ 'id ' => 'some-id ' ,
850+ ),
851+ );
852+
853+ $ html = '<div data-wp-bind--id="myPlugin::state.id">Content<br></br></div> ' ;
854+
855+ $ processed_html = $ this ->interactivity ->process_directives ( $ html );
856+
857+ $ this ->assertSame ( $ html , $ processed_html );
858+
859+ $ p = new WP_HTML_Tag_Processor ( $ processed_html );
860+ $ p ->next_tag ( 'div ' );
861+ $ this ->assertNull ( $ p ->get_attribute ( 'id ' ) );
862+ }
863+
836864 /**
837865 * Tests that the `process_directives` process the HTML outside a SVG tag.
838866 *
You can’t perform that action at this time.
0 commit comments