From 680222b674d9b0d5a9772c78e6fa4f02bccbb907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Wed, 28 Oct 2015 10:51:10 +0100 Subject: [PATCH] Button: Escape label option as text Fixes jquery/api.jqueryui.com#281 --- tests/unit/button/options.js | 15 +++++++++++++++ ui/widgets/button.js | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/unit/button/options.js b/tests/unit/button/options.js index 077d868e3b6..8dd5ecc2d14 100644 --- a/tests/unit/button/options.js +++ b/tests/unit/button/options.js @@ -86,6 +86,21 @@ test( "label, explicit value", function() { deepEqual( button.button( "option", "label" ), "xxx" ); } ); +test( "label, escape html", function() { + expect( 4 ); + var label = "
bloob
"; + var button = $( "#button" ).button( { + label: label + } ); + + deepEqual( button.text(), label ); + deepEqual( button.button( "option", "label" ), label ); + + button.button( "option", "label", label ); + deepEqual( button.text(), label ); + deepEqual( button.button( "option", "label" ), label ); +} ); + test( "label, default, with input type submit", function() { expect( 2 ); var button = $( "#submit" ).button(); diff --git a/ui/widgets/button.js b/ui/widgets/button.js index 50da9f9e22e..9dbaba0067c 100644 --- a/ui/widgets/button.js +++ b/ui/widgets/button.js @@ -93,7 +93,7 @@ $.widget( "ui.button", { if ( this.isInput ) { this.element.val( this.options.label ); } else { - this.element.html( this.options.label ); + this.element.text( this.options.label ); } } this._addClass( "ui-button", "ui-widget" ); @@ -249,7 +249,7 @@ $.widget( "ui.button", { // If there is an icon, append it, else nothing then append the value // this avoids removal of the icon when setting label text - this.element.html( value ); + this.element.text( value ); if ( this.icon ) { this._attachIcon( this.options.iconPosition ); this._attachIconSpace( this.options.iconPosition );