Closed Bug 1870434 Opened 6 months ago Closed 5 months ago

Date.parse rejects single numbers < 1000

Categories

(Core :: JavaScript: Standard Library, defect, P3)

defect

Tracking

()

RESOLVED FIXED
123 Branch
Tracking Status
firefox123 --- fixed

People

(Reporter: vinny.diehl, Assigned: vinny.diehl)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete, parity-chrome)

Attachments

(1 file, 1 obsolete file)

When faced with a single number < 1000, Firefox rejects the format, which other engines allow with differing behavior:

Input JavaScriptCore SpiderMonkey V8
"0" Fri Dec 31 -0001 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Sat Jan 01 2000 00:00:00 GMT-0700 (Mountain Standard Time)
"1" Sun Dec 31 0000 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Mon Jan 01 2001 00:00:00 GMT-0700 (Mountain Standard Time)
"12" Sat Dec 31 0011 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Sat Dec 01 2001 00:00:00 GMT-0700 (Mountain Standard Time)
"13" Mon Dec 31 0012 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Invalid Date
"31" Tue Dec 31 0030 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Invalid Date
"32" Wed Dec 31 0031 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Thu Jan 01 2032 00:00:00 GMT-0700 (Mountain Standard Time)
"50" Fri Dec 31 0049 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Sun Jan 01 1950 00:00:00 GMT-0700 (Mountain Standard Time)
"999" Mon Dec 31 0998 16:31:42 GMT-0728 (Mountain Standard Time) Invalid Date Tue Jan 01 0999 00:00:00 GMT-0728 (Mountain Standard Time)
"1000" Tue Dec 31 0999 16:31:42 GMT-0728 (Mountain Standard Time) Tue Dec 31 0999 16:31:42 GMT-0728 (Mountain Standard Time) Tue Dec 31 0999 16:31:42 GMT-0728 (Mountain Standard Time)

The Chrome behavior is as follows:

  • 0 is year 2000
  • 1-12 are parsed as a month (and the year is defaulted to 2001)
  • 13-31 are rejected
  • 31-49 are years 2031-2049
  • 50-99 are years 1950-1999
  • 100-999 are years 100-999
  • >= 1000 is a valid spec date and is parsed as such (works in all engines)

This is consistent with the dashed numeric date behavior when the year has < 4 digits. I personally think that the behavior for 1-31 is silly, and these should be seen as years if there is only a single number in the date string, however I don't wish to purposely create a third differing behavior between the browsers.

Assignee: nobody → vinny.diehl
Status: NEW → ASSIGNED
Depends on: 1870570
Attachment #9369108 - Attachment description: Bug 1870434 - Accept single number dates r?arai → WIP: Bug 1870434 - Accept single number dates r?arai
Priority: -- → P3
Attachment #9369806 - Attachment is obsolete: true
Attachment #9369108 - Attachment description: WIP: Bug 1870434 - Accept single number dates r?arai → Bug 1870434 - Accept single number dates r?arai,nchevobbe
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/efbca6aae3d9
Accept single number dates r=arai,devtools-reviewers,ochameau

Backed out with Bug 1871220 for causing remote failures on browser_RemoteValue.js (date error)

[task 2023-12-22T09:21:50.307Z] 09:21:50     INFO - TEST-PASS | remote/webdriver-bidi/test/browser/browser_RemoteValue.js | . Got expected error for date string: 10 - 
[task 2023-12-22T09:21:50.308Z] 09:21:50     INFO - Checking '20009'
[task 2023-12-22T09:21:50.309Z] 09:21:50     INFO - Buffered messages finished
[task 2023-12-22T09:21:50.316Z] 09:21:50     INFO - TEST-UNEXPECTED-FAIL | remote/webdriver-bidi/test/browser/browser_RemoteValue.js | Missing expected exception. Got expected error for date string: 20009 - {"filename":"chrome://mochitests/content/browser/remote/webdriver-bidi/test/browser/browser_RemoteValue.js","name":"test_deserializeDateLocalValueInvalidValues","sourceId":602,"lineNumber":624,"columnNumber":12,"sourceLine":"","asyncCause":null,"asyncCaller":null,"caller":{"filename":"chrome://mochikit/content/browser-test.js","name":"handleTask","sourceId":553,"lineNumber":1138,"columnNumber":26,"sourceLine":"","asyncCause":null,"asyncCaller":null,"caller":{"filename":"chrome://mochikit/content/browser-test.js","name":"_runTaskBasedTest","sourceId":553,"lineNumber":1210,"columnNumber":18,"sourceLine":"","asyncCause":null,"asyncCaller":{"filename":"chrome://mochikit/content/browser-test.js","name":"Tester_execTest","sourceId":553,"lineNumber":1352,"columnNumber":14,"sourceLine":"","asyncCause":null,"asyncCaller":null,"caller":{"filename":"chrome://mochikit/content/browser-test.js","name":"nextTest/<","sourceId":553,"lineNumber":1127,"columnNumber":14,"sourceLine":"","asyncCause":null,"asyncCaller":null,"caller":{"filename":"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js","name":"SimpleTest.waitForFocus/<","sourceId":580,"lineNumber":1058,"columnNumber":13,"sourceLine":"","asyncCause":null,"asyncCaller":null,"caller":null,"formattedStack":"SimpleTest.waitForFocus/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1058:13\n","nativeSavedFrame":{}},"formattedStack":"nextTest/<@chrome://mochikit/content/browser-test.js:1127:14\nSimpleTest.waitForFocus/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1058:13\n","nativeSavedFrame":{}},"formattedStack":"async*Tester_execTest@chrome://mochikit/content/browser-test.js:1352:14\nnextTest/<@chrome://mochikit/content/browser-test.js:1127:14\nSimpleTest.waitForFocus/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1058:13\n","nativeSavedFrame":{}},"caller":null,"formattedStack":"_runTaskBasedTest@chrome://mochikit/content/browser-test.js:1210:18\nasync*Tester_execTest@chrome://mochikit/content/browser-test.js:1352:14\nnextTest/<@chrome://mochikit/content/browser-test.js:1127:14\nSimpleTest.waitForFocus/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1058:13\n","nativeSavedFrame":{}},"formattedStack":"handleTask@chrome://mochikit/content/browser-test.js:1138:26\n_runTaskBasedTest@chrome://mochikit/content/browser-test.js:1210:18\nasync*Tester_execTest@chrome://mochikit/content/browser-test.js:1352:14\nnextTest/<@chrome://mochikit/content/browser-test.js:1127:14\nSimpleTest.waitForFocus/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1058:13\n","nativeSavedFrame":{}},"formattedStack":"test_deserializeDateLocalValueInvalidValues@chrome://mochitests/content/browser/remote/webdriver-bidi/test/browser/browser_RemoteValue.js:624:12\nhandleTask@chrome://mochikit/content/browser-test.js:1138:26\n_runTaskBasedTest@chrome://mochikit/content/browser-test.js:1210:18\nasync*Tester_execTest@chrome://mochikit/content/browser-test.js:1352:14\nnextTest/<@chrome://mochikit/content/browser-test.js:1127:14\nSimpleTest.waitForFocus/<@chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:1058:13\n","nativeSavedFrame":{}}
[task 2023-12-22T09:21:50.316Z] 09:21:50     INFO - Stack trace:
[task 2023-12-22T09:21:50.317Z] 09:21:50     INFO - chrome://mochitests/content/browser/remote/webdriver-bidi/test/browser/browser_RemoteValue.js:test_deserializeDateLocalValueInvalidValues:624
[task 2023-12-22T09:21:50.317Z] 09:21:50     INFO - chrome://mochikit/content/browser-test.js:handleTask:1138
[task 2023-12-22T09:21:50.317Z] 09:21:50     INFO - chrome://mochikit/content/browser-test.js:_runTaskBasedTest:1210
[task 2023-12-22T09:21:50.317Z] 09:21:50     INFO - chrome://mochikit/content/browser-test.js:Tester_execTest:1352
[task 2023-12-22T09:21:50.318Z] 09:21:50     INFO - chrome://mochikit/content/browser-test.js:nextTest/<:1127
[task 2023-12-22T09:21:50.318Z] 09:21:50     INFO - chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:SimpleTest.waitForFocus/<:1058
[task 2023-12-22T09:21:50.319Z] 09:21:50     INFO - TEST-PASS | remote/webdriver-bidi/test/browser/browser_RemoteValue.js | . Got expected error for date string: 20009 - 
Flags: needinfo?(vinny.diehl)

I believe this error SUMMARY: AddressSanitizer: heap-buffer-overflow /builds/worker/checkouts/gecko/js/src/jsdate.cpp:1908 in ParseDate was also caused by this patch.

Failure log: https://treeherder.mozilla.org/logviewer?job_id=441118042&repo=autoland&lineNumber=11888

Flags: needinfo?(vinny.diehl)
Attachment #9369108 - Attachment description: Bug 1870434 - Accept single number dates r?arai,nchevobbe → Bug 1870434 - Accept single number dates r?arai
Depends on: 1872116
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/9660032084db
Accept single number dates r=arai,devtools-reviewers,ochameau
Status: ASSIGNED → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → 123 Branch
Keywords: dev-doc-needed
Regressions: 1881930
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: