Skip to content

Commit

Permalink
fixes #5502 date parse to accept time zone offset
Browse files Browse the repository at this point in the history
  • Loading branch information
duongnhn committed Aug 16, 2018
1 parent 19738b7 commit 73b17dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/Runtime/Library/DateImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,23 @@ namespace Js {
goto LError;
}

for (lwT = ch - '0'; !FBig(*pch) && isdigit(*pch); pch++)
for (lwT = ch - '0'; ; pch++)
{
// for time zone offset HH:mm, we already got HH so skip ':' and grab mm
if (((ss == ssAddOffset) || (ss == ssSubOffset)) && (*pch == ':'))
{
continue;
}
if (FBig(*pch) || !isdigit(*pch))
{
break;
}
// to avoid overflow
if (pch - pchBase > 6)
{
goto LError;
}
// convert string to number, e.g. 07:30 -> 730
lwT = lwT * 10 + *pch - '0';
}

Expand All @@ -1292,6 +1302,7 @@ namespace Js {

if (lwNil != lwOffset)
goto LError;
// convert into minutes, e.g. 730 -> 7*60+30
lwOffset = lwT < 24 ? lwT * 60 :
(lwT % 100) + (lwT / 100) * 60;
if (ssSubOffset == ss)
Expand Down
10 changes: 6 additions & 4 deletions test/Date/parseInvalidISO.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ Invalid Date
Invalid Date

0001-01-01T01:01:01.001+25:00
Invalid Date
0000-12-31T00:01:01.001Z
-62135683138999 === -62135683138999

0001-01-01T01:60:01.001Z
Invalid Date

0001-01-01T01:01:01.001+00:60
Invalid Date
0001-01-01T00:01:01.001Z
-62135596738999 === -62135596738999

0001-01-01T01:01:60.001Z
Invalid Date
Expand All @@ -39,8 +41,8 @@ Invalid Date
Invalid Date

Total: 11
Accepted: 0
Rejected: 11
Accepted: 2
Rejected: 9
Failed: 0

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 73b17dd

Please sign in to comment.