From: Michał Gołębiowski-Owczarek Date: Tue, 11 May 2021 22:59:42 +0000 (+0200) Subject: Datepicker: Make sure text option are text, shorten HTML strings X-Git-Tag: 1.13.0-alpha.1~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=afe20b79a64266e64011f34b26a30b3d1c62fd47;p=jquery-ui.git Datepicker: Make sure text option are text, shorten HTML strings Instead of using enormous HTML strings, various elements are now constructed using jQuery APIs. This makes it more obvious user-provided data is used correctly. Fixes #15284 Closes gh-1953 --- diff --git a/tests/unit/datepicker/options.js b/tests/unit/datepicker/options.js index e5e938a0f..e58b9a75d 100644 --- a/tests/unit/datepicker/options.js +++ b/tests/unit/datepicker/options.js @@ -1171,4 +1171,55 @@ QUnit.test( "Ticket 7602: Stop datepicker from appearing with beforeShow event h inp.datepicker( "destroy" ); } ); +QUnit.test( "Ticket #15284: escaping text parameters", function( assert ) { + assert.expect( 7 ); + + var done = assert.async(); + + var qf = $( "#qunit-fixture" ); + + window.uiGlobalXss = []; + + var inp = testHelper.init( "#inp", { + showButtonPanel: true, + showOn: "both", + prevText: "", + nextText: "", + currentText: "", + closeText: "", + buttonText: "", + appendText: "" + } ); + + var dp = $( "#ui-datepicker-div" ); + + testHelper.onFocus( inp, function() { + assert.equal( dp.find( ".ui-datepicker-prev" ).text().trim(), + "", + "prevText escaped" ); + assert.equal( dp.find( ".ui-datepicker-next" ).text().trim(), + "", + "nextText escaped" ); + assert.equal( dp.find( ".ui-datepicker-current" ).text().trim(), + "", + "currentText escaped" ); + assert.equal( dp.find( ".ui-datepicker-close" ).text().trim(), + "", + "closeText escaped" ); + + assert.equal( qf.find( ".ui-datepicker-trigger" ).text().trim(), + "", + "buttonText escaped" ); + assert.equal( qf.find( ".ui-datepicker-append" ).text().trim(), + "", + "appendText escaped" ); + + assert.deepEqual( window.uiGlobalXss, [], "No XSS" ); + + delete window.uiGlobalXss; + inp.datepicker( "hide" ).datepicker( "destroy" ); + done(); + } ); +} ); + } ); diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js index f03e075cd..4fd8843cf 100644 --- a/ui/widgets/datepicker.js +++ b/ui/widgets/datepicker.js @@ -240,7 +240,9 @@ $.extend( Datepicker.prototype, { inst.append.remove(); } if ( appendText ) { - inst.append = $( "" + appendText + "" ); + inst.append = $( "" ) + .addClass( this._appendClass ) + .text( appendText ); input[ isRTL ? "before" : "after" ]( inst.append ); } @@ -257,12 +259,32 @@ $.extend( Datepicker.prototype, { if ( showOn === "button" || showOn === "both" ) { // pop-up date picker when button clicked buttonText = this._get( inst, "buttonText" ); buttonImage = this._get( inst, "buttonImage" ); - inst.trigger = $( this._get( inst, "buttonImageOnly" ) ? - $( "" ).addClass( this._triggerClass ). - attr( { src: buttonImage, alt: buttonText, title: buttonText } ) : - $( "" ).addClass( this._triggerClass ). - html( !buttonImage ? buttonText : $( "" ).attr( - { src:buttonImage, alt:buttonText, title:buttonText } ) ) ); + + if ( this._get( inst, "buttonImageOnly" ) ) { + inst.trigger = $( "" ) + .addClass( this._triggerClass ) + .attr( { + src: buttonImage, + alt: buttonText, + title: buttonText + } ); + } else { + inst.trigger = $( "" : "" ); - - buttonPanel = ( showButtonPanel ) ? "
" + ( isRTL ? controls : "" ) + - ( this._isInRange( inst, gotoDate ) ? "" : "" ) + ( isRTL ? "" : controls ) + "
" : ""; + controls = ""; + if ( !inst.inline ) { + controls = $( "