Interactivity API: Prevent warning when using a bind directive with a short attribute name.

Adds new tests and improves existing ones by using `assertSame` to do type comparison as well.

Reviewed by gziolo.
Merges [57835] to the to the 6.5 branch.

Props jonsurrell, cbravobernal, swissspidy, gziolo.
Fixes #60758.
Built from https://develop.svn.wordpress.org/branches/6.5@57837


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57338 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-03-15 11:18:19 +00:00
parent 9eed18532d
commit 4af7fa8ec0
2 changed files with 12 additions and 3 deletions

View File

@ -591,7 +591,13 @@ final class WP_Interactivity_API {
$attribute_value = $p->get_attribute( $attribute_name );
$result = $this->evaluate( $attribute_value, end( $namespace_stack ), end( $context_stack ) );
if ( null !== $result && ( false !== $result || '-' === $bound_attribute[4] ) ) {
if (
null !== $result &&
(
false !== $result ||
( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] )
)
) {
/*
* If the result of the evaluation is a boolean and the attribute is
* `aria-` or `data-, convert it to a string "true" or "false". It
@ -599,7 +605,10 @@ final class WP_Interactivity_API {
* replicate what Preact will later do in the client:
* https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136
*/
if ( is_bool( $result ) && '-' === $bound_attribute[4] ) {
if (
is_bool( $result ) &&
( strlen( $bound_attribute ) > 5 && '-' === $bound_attribute[4] )
) {
$result = $result ? 'true' : 'false';
}
$p->set_attribute( $bound_attribute, $result );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5-RC2-57834';
$wp_version = '6.5-RC2-57837';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.