diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index ab0b88693a..31352d2e88 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -1815,6 +1815,7 @@ class WP_HTML_Tag_Processor { * For string attributes, the value is escaped using the `esc_attr` function. * * @since 6.2.0 + * @since 6.2.1 Fix: Only create a single update for multiple calls with case-variant attribute names. * * @param string $name The attribute name to target. * @param string|bool $value The new attribute value. @@ -1907,8 +1908,8 @@ class WP_HTML_Tag_Processor { * * Result:
*/ - $existing_attribute = $this->attributes[ $comparable_name ]; - $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement( + $existing_attribute = $this->attributes[ $comparable_name ]; + $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement( $existing_attribute->start, $existing_attribute->end, $updated_attribute diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php index 6b0c263c5d..39d8fd3550 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php @@ -962,6 +962,24 @@ class Tests_HtmlApi_wpHtmlTagProcessor extends WP_UnitTestCase { ); } + /** + * Ensures that when setting an attribute multiple times that only + * one update flushes out into the updated HTML. + * + * @ticket 58146 + * + * @covers WP_HTML_Tag_Processor::set_attribute + */ + public function test_set_attribute_with_case_variants_updates_only_the_original_first_copy() { + $p = new WP_HTML_Tag_Processor( '