File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
tests/phpunit/tests/interactivity-api Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1212 * @coversDefaultClass WP_Interactivity_API_Directives_Processor
1313 */
1414class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_UnitTestCase {
15+
16+ /**
17+ * Regression: _process_directives should not fatal when encountering malformed markup
18+ * (e.g., a stray </br>) that causes get_attribute_names_with_prefix() to return null.
19+ *
20+ * Before the fix: PHP 8+ threw a TypeError from count(null).
21+ */
22+ public function test_process_directives_handles_noncountable_each_child_attrs () {
23+ $ html = '<div><br></br><span data-wp-bind--text="state.foo">x</span></div> ' ;
24+
25+ $ api = new WP_Interactivity_API ();
26+
27+ $ ref = new ReflectionClass ( $ api );
28+ $ method = $ ref ->getMethod ( '_process_directives ' );
29+ $ method ->setAccessible ( true );
30+
31+ // This would throw if there is an error.
32+ $ processed = $ method ->invoke ( $ api , $ html );
33+
34+ $ this ->assertIsString ( $ processed );
35+ $ this ->assertStringContainsString ( '<span ' , $ processed );
36+ $ this ->assertStringContainsString ( 'data-wp-bind--text ' , $ processed );
37+
38+ // Assert content still intact despite the malformed </br>.
39+ $ this ->assertStringContainsString ( '<div> ' , $ processed );
40+ }
41+
42+
1543 /**
1644 * Tests the `get_content_between_balanced_template_tags` method on template
1745 * tags.
You can’t perform that action at this time.
0 commit comments