Open Bug 1922631 Opened 2 years ago Updated 4 months ago

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)

Firefox 131
defect

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)

Attached file dateparse.html —

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.

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.

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.

Component: Untriaged → JavaScript Engine
Product: Firefox → Core

Vinny, would you be interested in taking a peek at this (if not, no worries)

Severity: -- → S3
Flags: needinfo?(vinny.diehl)
Priority: -- → P3

regression points to Bug 1870434 - Accept single number dates r=arai,devtools-reviewers,ochameau

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.

Status: UNCONFIRMED → NEW
Component: JavaScript Engine → JavaScript: Standard Library
Ever confirmed: true
Flags: needinfo?(vinny.diehl)
Keywords: regression
Regressed by: 1870434

The component has been changed since the backlog priority was decided, so we're resetting it.
For more information, please visit BugBot documentation.

Priority: P3 → --

Set release status flags based on info from the regressing bug 1870434

Priority: -- → P3

Set release status flags based on info from the regressing bug 1870434

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: