Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,12 @@ private function _process_directives( string $html ) {
array_pop( $tag_stack );
}
} else {
if ( 0 !== count( $p->get_attribute_names_with_prefix( 'data-wp-each-child' ) ) ) {
$each_child_attrs = $p->get_attribute_names_with_prefix( 'data-wp-each-child' );
if ( null === $each_child_attrs ) {
continue;
}

if ( null !== $each_child_attrs && 0 !== count( $each_child_attrs ) ) {
/*
* If the tag has a `data-wp-each-child` directive, jump to its closer
* tag because those tags have already been processed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@
* @coversDefaultClass WP_Interactivity_API_Directives_Processor
*/
class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_UnitTestCase {

/**
* Regression: _process_directives should not fatal when encountering malformed markup
* (e.g., a stray </br>) that causes get_attribute_names_with_prefix() to return null.
*
* Before the fix: PHP 8+ threw a TypeError from count(null).
*/
public function test_process_directives_handles_noncountable_each_child_attrs() {
$html = '<div><br></br><span data-wp-bind--text="state.foo">x</span></div>';

$api = new WP_Interactivity_API();

$ref = new ReflectionClass( $api );
$method = $ref->getMethod( '_process_directives' );
$method->setAccessible( true );

// This would throw if there is an error.
$processed = $method->invoke( $api, $html );

$this->assertIsString( $processed );
$this->assertStringContainsString( '<span', $processed );
$this->assertStringContainsString( 'data-wp-bind--text', $processed );

// Assert content still intact despite the malformed </br>.
$this->assertStringContainsString( '<div>', $processed );
}


/**
* Tests the `get_content_between_balanced_template_tags` method on template
* tags.
Expand Down
Loading