Skip to content

Commit 76e2b98

Browse files
committed
Updated guard against unparsed characters to allow extra characters as long as they are separated from the date by whitespace. This maintains compatibility with timepicker extensions.
Fixes #7244 - Datepicker: parseDate() does not throw an exception for long years
1 parent 5c34cea commit 76e2b98

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

tests/unit/datepicker/datepicker_tickets.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,22 @@ test('Ticket 6827: formatDate day of year calculation is wrong during day lights
3030
});
3131

3232
test('Ticket #7244: date parser does not fail when too many numbers are passed into the date function', function() {
33-
expect(1);
33+
var date;
3434
try{
35-
var date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881');
35+
date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881');
36+
ok(false, "Did not properly detect an invalid date");
3637
}catch(e){
3738
ok("invalid date detected");
3839
}
40+
41+
try {
42+
date = $.datepicker.parseDate('dd/mm/yy', '18/04/1988 @ 2:43 pm');
43+
equal(date.getDate(), 18);
44+
equal(date.getMonth(), 3);
45+
equal(date.getFullYear(), 1988);
46+
} catch(e) {
47+
ok(false, "Did not properly parse date with extra text separated by whitespace");
48+
}
3949
});
4050

4151
})(jQuery);

ui/jquery.ui.datepicker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,10 @@ $.extend(Datepicker.prototype, {
10951095
}
10961096
}
10971097
if (iValue < value.length){
1098-
throw "Extra/unparsed characters found in date: " + value.substring(iValue);
1098+
var extra = value.substr(iValue);
1099+
if (!/^\s+/.test(extra)) {
1100+
throw "Extra/unparsed characters found in date: " + extra;
1101+
}
10991102
}
11001103
if (year == -1)
11011104
year = new Date().getFullYear();

0 commit comments

Comments
 (0)