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.



git-svn-id: https://develop.svn.wordpress.org/trunk@46734 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock 2019-11-15 23:22:19 +00:00
parent e879f7d457
commit 90ad63f2ce
1 changed files with 7 additions and 4 deletions

View File

@ -550,16 +550,19 @@ class WP_Admin_Bar {
if ( $has_link ) {
$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
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 {
$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
echo '<div class="ab-item ab-empty-item"' . $aria_attributes;
}
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 ] ) . "'";
}
}