]> source.dussan.org Git - jquery-ui.git/commitdiff
Updated guard against unparsed characters to allow extra characters as long as they... 375/head
authorPhilip Graham <philip.robert.graham@gmail.com>
Tue, 28 Jun 2011 16:40:28 +0000 (16:40 +0000)
committerPhilip Graham <philip.robert.graham@gmail.com>
Tue, 28 Jun 2011 16:40:28 +0000 (16:40 +0000)
Fixes #7244 - Datepicker: parseDate() does not throw an exception for long years

tests/unit/datepicker/datepicker_tickets.js
ui/jquery.ui.datepicker.js

index d5249f9051dced0afbfb77ea36ea80f0107ffa6b..10647eb136bb800b16ab355fc07fce2b0caf2c44 100644 (file)
@@ -30,12 +30,22 @@ test('Ticket 6827: formatDate day of year calculation is wrong during day lights
 });
 
 test('Ticket #7244: date parser does not fail when too many numbers are passed into the date function', function() {
-    expect(1);
+    var date;
     try{
-        var date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881');
+        date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881');
+        ok(false, "Did not properly detect an invalid date");
     }catch(e){
         ok("invalid date detected");
     }
+
+    try {
+      date = $.datepicker.parseDate('dd/mm/yy', '18/04/1988 @ 2:43 pm');
+      equal(date.getDate(), 18);
+      equal(date.getMonth(), 3);
+      equal(date.getFullYear(), 1988);
+    } catch(e) {
+      ok(false, "Did not properly parse date with extra text separated by whitespace");
+    }
 });
 
 })(jQuery);
index 1d3de7740cd327aefb7592f698fd317fe07866f6..45107c969a504c63300c65cc746d17ec63e88b66 100644 (file)
@@ -1095,7 +1095,10 @@ $.extend(Datepicker.prototype, {
                                }
                }
                if (iValue < value.length){
-                       throw "Extra/unparsed characters found in date: " + value.substring(iValue);
+                       var extra = value.substr(iValue);
+                       if (!/^\s+/.test(extra)) {
+                               throw "Extra/unparsed characters found in date: " + extra;
+                       }
                }
                if (year == -1)
                        year = new Date().getFullYear();