Prevent undesired Date parsing

Native Date parsing is unpredictable and will occasionally turn a string
like "/foo/1" into a valid date of Jan 1, 2001.  This can be prevented
by not parsing a string that begins with a slash.

It's likely that this is a rare case, but it's annoying when it does
come up.
This commit is contained in:
Douglas Brown 2016-09-15 11:32:34 -04:00
parent 91851e2025
commit 391e7f43f5
2 changed files with 5 additions and 1 deletions

View file

@ -15,7 +15,7 @@ module.exports = function(string) {
if (value !== "" && !isNaN(number) || value === "NaN") value = number
else if (value === "true") value = true
else if (value === "false") value = false
else {
else if (value.charAt(0) !== "/") {
var date = new Date(value)
if (!isNaN(date.getTime())) value = date
}