Toolbar: Properly escape the onclick attribute.

The onclick attribute was being escaped twice, once with `esc_js` and again with `esc_attr`.

Fixes #48117.
Props tmatsuur, dinhtungdu.


Built from https://develop.svn.wordpress.org/trunk@46734


git-svn-id: http://core.svn.wordpress.org/trunk@46534 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2019-11-15 23:24:02 +00:00
parent 3a735ec87a
commit ba7170de9c
2 changed files with 8 additions and 5 deletions

View File

@ -550,16 +550,19 @@ class WP_Admin_Bar {
if ( $has_link ) { if ( $has_link ) {
$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' ); $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'"; echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'";
if ( ! empty( $node->meta['onclick'] ) ) {
echo ' onclick="' . esc_js( $node->meta['onclick'] ) . '"';
}
} else { } else {
$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' ); $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
echo '<div class="ab-item ab-empty-item"' . $aria_attributes; echo '<div class="ab-item ab-empty-item"' . $aria_attributes;
} }
foreach ( $attributes as $attribute ) { foreach ( $attributes as $attribute ) {
if ( ! empty( $node->meta[ $attribute ] ) ) { if ( empty( $node->meta[ $attribute ] ) ) {
continue;
}
if ( 'onclick' === $attribute ) {
echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'";
} else {
echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'"; echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'";
} }
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.4-alpha-46733'; $wp_version = '5.4-alpha-46734';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.