Skip to content

Commit 5730374

Browse files
rclmenezestjvantoll
authored andcommitted
Datepicker: reject dates with two year digits when expecting 'yy'
Fixes #8353 Closes jquerygh-1248
1 parent bef2c45 commit 5730374

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

tests/unit/datepicker/datepicker_options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ test("parseDate", function() {
962962
});
963963

964964
test("parseDateErrors", function() {
965-
expect( 17 );
965+
expect( 18 );
966966
TestHelpers.datepicker.init("#inp");
967967
var fr, settings;
968968
function expectError(expr, value, error) {
@@ -986,6 +986,8 @@ test("parseDateErrors", function() {
986986
"3 Feb 01 - d m y", "Missing number at position 2");
987987
expectError(function() { $.datepicker.parseDate("dd mm yy", "3 Feb 01"); },
988988
"3 Feb 01 - dd mm yy", "Missing number at position 2");
989+
expectError(function() { $.datepicker.parseDate("mm dd yy", "2 1 01"); },
990+
"2 1 01 - dd mm yy", "Missing number at position 4");
989991
expectError(function() { $.datepicker.parseDate("d m y", "3 2 AD01"); },
990992
"3 2 AD01 - d m y", "Missing number at position 4");
991993
expectError(function() { $.datepicker.parseDate("d m yy", "3 2 AD01"); },

ui/datepicker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ $.extend(Datepicker.prototype, {
11381138
var isDoubled = lookAhead(match),
11391139
size = (match === "@" ? 14 : (match === "!" ? 20 :
11401140
(match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))),
1141-
digits = new RegExp("^\\d{1," + size + "}"),
1141+
minSize = (match === "y" ? size : 1),
1142+
digits = new RegExp("^\\d{" + minSize + "," + size + "}"),
11421143
num = value.substring(iValue).match(digits);
11431144
if (!num) {
11441145
throw "Missing number at position " + iValue;

0 commit comments

Comments
 (0)