From e05559eb162b0a3b1c090604a144262de2f9a5d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Wed, 18 May 2011 17:30:26 +0200 Subject: [PATCH] There's no guard against unparsed characters at the end of the date string, any extra characters are just ignored Fixes #7244 - Datepicker: parseDate() does not throw an exception for long years (cherry picked from commit 92b0f6702a9408f4bd7d71ccca7e0e851d0efc6b) --- tests/unit/datepicker/datepicker_tickets.js | 9 +++++++++ ui/jquery.ui.datepicker.js | 3 +++ 2 files changed, 12 insertions(+) diff --git a/tests/unit/datepicker/datepicker_tickets.js b/tests/unit/datepicker/datepicker_tickets.js index 841e40405..c7fde60de 100644 --- a/tests/unit/datepicker/datepicker_tickets.js +++ b/tests/unit/datepicker/datepicker_tickets.js @@ -34,4 +34,13 @@ test('Ticket 6827: formatDate day of year calculation is wrong during day lights equals(time, "089"); }); +test('Ticket #7244: date parser does not fail when too many numbers are passed into the date function', function() { + expect(1); + try{ + var date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881'); + }catch(e){ + ok("invalid date detected"); + } +}); + })(jQuery); diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js index 045fa1d92..6681d693c 100644 --- a/ui/jquery.ui.datepicker.js +++ b/ui/jquery.ui.datepicker.js @@ -1078,6 +1078,9 @@ $.extend(Datepicker.prototype, { checkLiteral(); } } + if (iValue < value.length){ + throw "Extra/unparsed characters found in date: " + value.substring(iValue); + } if (year == -1) year = new Date().getFullYear(); else if (year < 100) -- 2.39.5