Skip to content

Commit e038777

Browse files
committed
HTML API: Indicate when WordPress rejects attribute updates.
When setting an an attribute value in the HTML API, WordPress may reject an update based on rules in `kses`. In these cases, the return value from an escaping function will be an empty string, and the HTML API should reject the update. Unfortunately, it currently reports that it updates the attribute but sets an empty string value, which is misleading. In this patch, the HTML API will refuse the attribute update and return false to indicate as much when WordPress rejects the updates. Developed in WordPress/wordpress-develop#7114 Discussed in https://core.trac.wordpress.org/ticket/61719 Follow-up to [58472]. Props: amitraj2203, dmsnell, mukesh27. Fixes #61719. Built from https://develop.svn.wordpress.org/trunk@58844 git-svn-id: https://core.svn.wordpress.org/trunk@58240 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 6255b33 commit e038777

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,12 @@ public function set_attribute( $name, $value ): bool {
31973197
* @see https://html.spec.whatwg.org/#attributes-3
31983198
*/
31993199
$escaped_new_value = in_array( $comparable_name, wp_kses_uri_attributes() ) ? esc_url( $value ) : esc_attr( $value );
3200+
3201+
// If the escaping functions wiped out the update, reject it and indicate it was rejected.
3202+
if ( '' === $escaped_new_value && '' !== $value ) {
3203+
return false;
3204+
}
3205+
32003206
$updated_attribute = "{$name}=\"{$escaped_new_value}\"";
32013207
}
32023208

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.7-alpha-58843';
19+
$wp_version = '6.7-alpha-58844';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)