Bug 1551893: Require strict zero-pad for time element if T exists r=arai
authorKagami Sascha Rosylight <saschanaz@outlook.com>
Thu, 16 May 2019 18:02:58 +0000
changeset 474290 00a761b7fce83bfe255ac76a65641cd83c5c7915
parent 474289 44a79556ff86f3c3ead666fc2fd973e8b24681ea
child 474291 2f69f765ef513a61ad39b4fc2b294135cf514e98
push id113144
push usershindli@mozilla.com
push dateFri, 17 May 2019 16:44:55 +0000
treeherdermozilla-inbound@f4c4b796f845 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1551893
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551893: Require strict zero-pad for time element if T exists r=arai Make T as a strictness marker for ISO8601 time element, as it already does for the date element. Differential Revision: https://phabricator.services.mozilla.com/D31418
js/src/jsdate.cpp
js/src/tests/non262/Date/non-iso.js
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -914,16 +914,17 @@ static bool ParseISOStyleDate(const Char
   size_t hour = 0;
   size_t min = 0;
   size_t sec = 0;
   double frac = 0;
   bool isLocalTime = false;
   size_t tzHour = 0;
   size_t tzMin = 0;
   bool isPermissive = false;
+  bool isStrict = false;
 
 #define PEEK(ch) (i < length && s[i] == ch)
 
 #define NEED(ch)                   \
   if (i >= length || s[i] != ch) { \
     return false;                  \
   } else {                         \
     ++i;                           \
@@ -949,17 +950,21 @@ static bool ParseISOStyleDate(const Char
   }
 
 #define NEED_NDIGITS_OR_LESS(n, field)                 \
   pre = i;                                             \
   if (!ParseDigitsNOrLess(n, &field, s, &i, length)) { \
     return false;                                      \
   }                                                    \
   if (i < pre + (n)) {                                 \
-    isPermissive = true;                               \
+    if (isStrict) {                                    \
+      return false;                                    \
+    } else {                                           \
+      isPermissive = true;                             \
+    }                                                  \
   }
 
   if (PEEK('+') || PEEK('-')) {
     if (PEEK('-')) {
       dateMul = -1;
     }
     ++i;
     NEED_NDIGITS(6, year);
@@ -973,16 +978,17 @@ static bool ParseISOStyleDate(const Char
 
 done_date:
   if (PEEK('T')) {
     if (isPermissive) {
       // Require standard format "[+00]1970-01-01" if a time part marker "T"
       // exists
       return false;
     }
+    isStrict = true;
     i++;
   } else if (PEEK(' ')) {
     i++;
   } else {
     goto done;
   }
 
   NEED_NDIGITS_OR_LESS(2, hour);
--- a/js/src/tests/non262/Date/non-iso.js
+++ b/js/src/tests/non262/Date/non-iso.js
@@ -26,23 +26,23 @@ assertEq(new Date("1997-3-8 11:19:20").g
          new Date("1997-03-08T11:19:20").getTime());
 assertEq(new Date("+001997-3-8 11:19:20").getTime(),
          new Date("1997-03-08T11:19:20").getTime());
 assertEq(new Date("+001997-03-8 11:19:20").getTime(),
          new Date("1997-03-08T11:19:20").getTime());
 assertEq(new Date("1997-03-08 11:19").getTime(),
          new Date("1997-03-08T11:19").getTime());
 assertEq(new Date("1997-03-08 1:19").getTime(),
-         new Date("1997-03-08T1:19").getTime());
+         new Date("1997-03-08T01:19").getTime());
 assertEq(new Date("1997-03-08 1:1").getTime(),
-         new Date("1997-03-08T1:1").getTime());
+         new Date("1997-03-08T01:01").getTime());
 assertEq(new Date("1997-03-08 1:1:01").getTime(),
-         new Date("1997-03-08T1:1:01").getTime());
+         new Date("1997-03-08T01:01:01").getTime());
 assertEq(new Date("1997-03-08 1:1:1").getTime(),
-         new Date("1997-03-08T1:1:1").getTime());
+         new Date("1997-03-08T01:01:01").getTime());
 assertEq(new Date("1997-03-08 11").getTime(),
          new Date("1997-03-08T11").getTime()); // Date(NaN)
 assertEq(new Date("1997-03-08").getTime(),
          new Date("1997-03-08").getTime());
 assertEq(new Date("1997-03-8").getTime(),
          new Date("1997-03-08").getTime());
 assertEq(new Date("1997-3-8").getTime(),
          new Date("1997-03-08").getTime());
@@ -53,19 +53,25 @@ assertEq(new Date("1997-3-8T11:19:20").g
 assertEq(new Date("1997-03-8T11:19:20").getTime(),
          new Date(NaN).getTime());
 assertEq(new Date("+001997-3-8T11:19:20").getTime(),
          new Date(NaN).getTime());
 assertEq(new Date("+001997-3-08T11:19:20").getTime(),
          new Date(NaN).getTime());
 assertEq(new Date("1997-3-8 :00:01").getTime(),
          new Date(NaN).getTime());
-assertEq(new Date("1997-3-8 :00:01").getTime(),
+assertEq(new Date("1997-3-8 01::01").getTime(),
          new Date(NaN).getTime());
-assertEq(new Date("1997-3-8 01::01").getTime(),
+assertEq(new Date("1997-03-08T1:19").getTime(),
+         new Date(NaN).getTime());         
+assertEq(new Date("1997-03-08T1:1").getTime(),
+         new Date(NaN).getTime());
+assertEq(new Date("1997-03-08T1:1:01").getTime(),
+         new Date(NaN).getTime());
+assertEq(new Date("1997-03-08T1:1:1").getTime(),
          new Date(NaN).getTime());
 
 /******************************************************************************/
 
 if (typeof reportCompare === "function")
   reportCompare(true, true);
 
 print("Tests complete");