From 573037423822fa04a1888e3bcc52243b9324c5e2 Mon Sep 17 00:00:00 2001 From: Rodrigo Menezes Date: Thu, 15 May 2014 17:16:09 -0400 Subject: [PATCH] Datepicker: reject dates with two year digits when expecting 'yy' Fixes #8353 Closes gh-1248 --- tests/unit/datepicker/datepicker_options.js | 4 +++- ui/datepicker.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js index bcb2d28dd..8dba48674 100644 --- a/tests/unit/datepicker/datepicker_options.js +++ b/tests/unit/datepicker/datepicker_options.js @@ -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) { @@ -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"); }, diff --git a/ui/datepicker.js b/ui/datepicker.js index 10b7d7eb5..46b6a5f4d 100644 --- a/ui/datepicker.js +++ b/ui/datepicker.js @@ -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;