Skip to content

Commit

Permalink
There's no guard against unparsed characters at the end of the date s…
Browse files Browse the repository at this point in the history
…tring, any extra characters are just ignored

Fixes #7244 - Datepicker: parseDate() does not throw an exception for long years
(cherry picked from commit 92b0f67)
  • Loading branch information
jzaefferer committed May 18, 2011
1 parent fab1729 commit e05559e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/unit/datepicker/datepicker_tickets.js
Expand Up @@ -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);
3 changes: 3 additions & 0 deletions ui/jquery.ui.datepicker.js
Expand Up @@ -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)
Expand Down

0 comments on commit e05559e

Please sign in to comment.