Date.parse not returning NaN for invalid string as long as it includes a month name or month abbreviation
Categories
(Core :: JavaScript: Standard Library, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox-esr115 | --- | unaffected |
| firefox-esr128 | --- | affected |
| firefox131 | --- | wontfix |
| firefox132 | --- | wontfix |
| firefox133 | --- | wontfix |
| firefox134 | --- | fix-optional |
People
(Reporter: claire.c, Unassigned)
References
(Blocks 1 open bug, Regression)
Details
(Keywords: regression)
Attachments
(1 file)
|
2.48 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0
Steps to reproduce:
This bug can be reproduced in the Developer Tools' Console tab. I've also attached an html file containing examples.
When parsing date strings with new Date or Date.parse, the browser accepts certain strings that shouldn't be interpreted as datetimes as valid dates (Date.parse returns an integer timestamp rather than NaN, new Date creates a valid Date object). This occurs when the passed string includes either a month name ("december") or a month abbreviation ("dec") and ends with a period "." or a space " "
Referring to the attached html file, see the testStrings array for example strings.
Actual results:
Date.parse returns an integer timestamp rather than NaN. new Date creates a valid Date object.
Referring to the attached file, all testStrings are accepted as valid datetime strings.
Expected results:
Date.parse should return NaN for strings that do not represent datetimes. new Date should create an invalid Date object.
Referring to the attached file, all testStrings should cause Date.parse to return NaN and new Date to create an invalid Date object.
| Reporter | ||
Comment 1•2 years ago
|
||
Under 'Actual Results', there's a typo, here's the correction:
Referring to the attached file, all testStrings except the first are accepted as valid datetime strings.
Comment 2•2 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::JavaScript Engine' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 3•2 years ago
|
||
Vinny, would you be interested in taking a peek at this (if not, no worries)
Comment 4•2 years ago
|
||
regression points to Bug 1870434 - Accept single number dates r=arai,devtools-reviewers,ochameau
Comment 5•2 years ago
|
||
Yeah, confirmed:
| Input | JavaScriptCore | SpiderMonkey | V8 |
|---|---|---|---|
"this string doesn't represent a date" |
NaN | NaN | NaN |
"Our district could decide who has the majority in Congress." |
NaN | 1007190000000 | NaN |
"Our district could decemberide who has the majority in Congress. This string ends with a space " |
NaN | 1007190000000 | NaN |
"This string ends with a space. Our district could decide who has the majority in Congress " |
NaN | 1007190000000 | NaN |
"The shrimp should be marinated in lime juice for half an hour." |
NaN | 983430000000 | NaN |
"The shrimp should be marchinated in lime juice for half an hour." |
NaN | 983430000000 | NaN |
"I set my alarm earlier than usual and rushed through my morning routine. When I arrived at the office, Novak, the lead engineer, was already at his desk." |
NaN | 1004598000000 | NaN |
"When I arrived at the office, Novemberak, the lead engineer, was already at his desk." |
NaN | 1004598000000 | NaN |
This bug could potentially cause strings to be inadvertently parsed as a date by software which uses Date.parse to do so, like we had in bug 1881930. I'll dig deeper into this when I get a chance.
Comment 6•2 years ago
|
||
The component has been changed since the backlog priority was decided, so we're resetting it.
For more information, please visit BugBot documentation.
Comment 7•2 years ago
|
||
Set release status flags based on info from the regressing bug 1870434
Updated•2 years ago
|
Updated•2 years ago
|
Comment 8•2 years ago
|
||
Set release status flags based on info from the regressing bug 1870434
Updated•2 years ago
|
Updated•1 year ago
|
Description
•