Skip to content

Commit 9d423e5

Browse files
fnagelscottgonzalez
authored andcommitted
Calendar: Sanitize active descendant id selector
1 parent 43f66b8 commit 9d423e5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ui/calendar.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ return $.widget( "ui.calendar", {
9999
// TODO: Handle for pickers with multiple months
100100
switch ( event.keyCode ) {
101101
case $.ui.keyCode.ENTER:
102-
this.element.find(
103-
"#" + this.grid.attr( "aria-activedescendant" ) + " > a:first"
104-
).mousedown();
102+
this.activeDescendant.mousedown();
105103
return;
106104
case $.ui.keyCode.PAGE_UP:
107105
this.date.adjust( event.altKey ? "Y" : "M", -1 );
@@ -147,7 +145,10 @@ return $.widget( "ui.calendar", {
147145
.attr( "aria-activedescendant", id )
148146
.find( ".ui-state-focus" )
149147
.removeClass( "ui-state-focus" );
150-
this.grid.find( "#" + id ).find ( "a" ).addClass( "ui-state-focus" );
148+
149+
this.activeDescendant = this.grid.find(
150+
this._sanitizeSelector( "#" + id ) + " > a"
151+
).addClass( "ui-state-focus" );
151152
},
152153

153154
_createCalendar: function() {
@@ -470,6 +471,10 @@ return $.widget( "ui.calendar", {
470471
return $( "<a>" ).text( this.labels[ key ] ).html();
471472
},
472473

474+
_sanitizeSelector: function( hash ) {
475+
return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
476+
},
477+
473478
_setHiddenPicker: function() {
474479
this.element.attr({
475480
"aria-hidden": "true",

0 commit comments

Comments
 (0)