Changeset 288411 in webkit


Ignore:
Timestamp:
Jan 22, 2022 4:00:38 PM (6 months ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Relax Date.parse requirement
https://bugs.webkit.org/show_bug.cgi?id=235468

Reviewed by Darin Adler.

JSTests:

  • stress/date-relaxed-separator.js: Added.

(shouldBe):

Source/WTF:

While the spec does not require accepting 't' / ' ' separator, ISO 8601 accepts it.
This is because ECMA262's Date format is *not* ISO 8601 (it is called simplification
of ISO 8601[1]).
This patch relaxes this strictness to accept more formats, which can be accepted in
the other engines too.

[1]: https://tc39.es/ecma262/#sec-date-time-string-format

  • wtf/DateMath.cpp:

(WTF::parseES5DateFromNullTerminatedCharacters):

LayoutTests:

  • js/date-parse-test-expected.txt:
  • js/script-tests/date-parse-test.js:
Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r288272 r288411  
     12022-01-21  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Relax Date.parse requirement
     4        https://bugs.webkit.org/show_bug.cgi?id=235468
     5
     6        Reviewed by Darin Adler.
     7
     8        * stress/date-relaxed-separator.js: Added.
     9        (shouldBe):
     10
    1112022-01-19  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/LayoutTests/ChangeLog

    r288409 r288411  
     12022-01-21  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Relax Date.parse requirement
     4        https://bugs.webkit.org/show_bug.cgi?id=235468
     5
     6        Reviewed by Darin Adler.
     7
     8        * js/date-parse-test-expected.txt:
     9        * js/script-tests/date-parse-test.js:
     10
    1112022-01-22  Alan Bujtas  <zalan@apple.com>
    212
  • trunk/LayoutTests/js/date-parse-test-expected.txt

    r254939 r288411  
    2828PASS Date.parse("1995-12-25T01:30:00+00:00 ") is NaN
    2929PASS Date.parse("1995-02-29T00:00:00Z") is NaN
    30 PASS Date.parse("1995-12-25 01:30:00Z") is NaN
     30PASS Date.parse("1995-12-25 01:30:00Z") == 819855000000 is true
    3131PASS Date.parse("1995-12-25T01:30:00z") is NaN
    3232PASS Number(Date.parse('1970')) is 0
  • trunk/LayoutTests/js/script-tests/date-parse-test.js

    r254939 r288411  
    6767testDateParseExact("1995-12-25T01:30:00+00:00 ", "NaN");
    6868testDateParseExact("1995-02-29T00:00:00Z", "NaN");
    69 testDateParseExact("1995-12-25 01:30:00Z", "NaN");
     69testDateParseExact("1995-12-25 01:30:00Z", "819855000000");
    7070testDateParseExact("1995-12-25T01:30:00z", "NaN");
    7171
  • trunk/Source/WTF/ChangeLog

    r288389 r288411  
     12022-01-21  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Relax Date.parse requirement
     4        https://bugs.webkit.org/show_bug.cgi?id=235468
     5
     6        Reviewed by Darin Adler.
     7
     8        While the spec does not require accepting 't' / ' ' separator, ISO 8601 accepts it.
     9        This is because ECMA262's Date format is *not* ISO 8601 (it is called simplification
     10        of ISO 8601[1]).
     11        This patch relaxes this strictness to accept more formats, which can be accepted in
     12        the other engines too.
     13
     14        [1]: https://tc39.es/ecma262/#sec-date-time-string-format
     15
     16        * wtf/DateMath.cpp:
     17        (WTF::parseES5DateFromNullTerminatedCharacters):
     18
    1192022-01-21  Sihui Liu  <sihui_liu@apple.com>
    220
  • trunk/Source/WTF/wtf/DateMath.cpp

    r278253 r288411  
    646646    // Look for a time portion.
    647647    // Note: As of ES2016, when a UTC offset is missing, date-time forms are local time while date-only forms are UTC.
    648     if (*currentPosition == 'T') {
     648    if (*currentPosition == 'T' || *currentPosition == 't' || *currentPosition == ' ') {
    649649        // Parse the time HH:mm[:ss[.sss]][Z|(+|-)(00:00|0000|00)]
    650650        currentPosition = parseES5TimePortion(currentPosition + 1, hours, minutes, seconds, milliseconds, isLocalTime, timeZoneSeconds);
Note: See TracChangeset for help on using the changeset viewer.