Skip to content

Commit

Permalink
Datepicker: reject dates with two year digits when expecting 'yy'
Browse files Browse the repository at this point in the history
Fixes #8353
Closes gh-1248
  • Loading branch information
rclmenezes authored and tjvantoll committed Jul 14, 2014
1 parent bef2c45 commit 5730374
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tests/unit/datepicker/datepicker_options.js
Expand Up @@ -962,7 +962,7 @@ test("parseDate", function() {
});

test("parseDateErrors", function() {
expect( 17 );
expect( 18 );
TestHelpers.datepicker.init("#inp");
var fr, settings;
function expectError(expr, value, error) {
Expand All @@ -986,6 +986,8 @@ test("parseDateErrors", function() {
"3 Feb 01 - d m y", "Missing number at position 2");
expectError(function() { $.datepicker.parseDate("dd mm yy", "3 Feb 01"); },
"3 Feb 01 - dd mm yy", "Missing number at position 2");
expectError(function() { $.datepicker.parseDate("mm dd yy", "2 1 01"); },
"2 1 01 - dd mm yy", "Missing number at position 4");
expectError(function() { $.datepicker.parseDate("d m y", "3 2 AD01"); },
"3 2 AD01 - d m y", "Missing number at position 4");
expectError(function() { $.datepicker.parseDate("d m yy", "3 2 AD01"); },
Expand Down
3 changes: 2 additions & 1 deletion ui/datepicker.js
Expand Up @@ -1138,7 +1138,8 @@ $.extend(Datepicker.prototype, {
var isDoubled = lookAhead(match),
size = (match === "@" ? 14 : (match === "!" ? 20 :
(match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))),
digits = new RegExp("^\\d{1," + size + "}"),
minSize = (match === "y" ? size : 1),
digits = new RegExp("^\\d{" + minSize + "," + size + "}"),
num = value.substring(iValue).match(digits);
if (!num) {
throw "Missing number at position " + iValue;
Expand Down

0 comments on commit 5730374

Please sign in to comment.