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:
parent
91851e2025
commit
391e7f43f5
2 changed files with 5 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue