Permalink
Browse files

[MERGE #5816 @mlfaw] Change Date.parse() to require a time component …

…when using an offset.

Merge pull request #5816 from mlfaw:mlfaw-date-parse2

Previously an input such as `2018-08-21+10:00` would interpret the offset as a time.
NaN is now returned instead. As a compatibility note, both Chrome and Firefox return NaN.

Previous pull-request: #5791
  • Loading branch information...
boingoing committed Nov 7, 2018
2 parents 3ee8aca + 05dda62 commit ffebc17a3db6c19508ce9dda50e077f171795a8d
Showing with 8 additions and 10 deletions.
  1. +4 −10 lib/Runtime/Library/DateImplementation.cpp
  2. +4 −0 test/Date/DateParse3.js
@@ -1118,19 +1118,13 @@ namespace Js {
continue;
}
case '+':
{
if (lwNil != lwTime)
{
ss = ssAddOffset;
}
continue;
}
case '-':
{
if (lwNil != lwTime)
if (lwNil == lwTime)
{
ss = ssSubOffset;
goto LError;
}
ss = (ch == '+') ? ssAddOffset : ssSubOffset;
continue;
}
}
@@ -1300,7 +1294,7 @@ namespace Js {
{
AssertMsg(isNextFieldDateNegativeVersion5 == false, "isNextFieldDateNegativeVersion5 == false");
if (lwNil != lwOffset)
if (lwNil != lwOffset || lwNil == lwTime)
goto LError;
// convert into minutes, e.g. 730 -> 7*60+30
lwOffset = lwT < 24 ? lwT * 60 :
View
@@ -24,6 +24,10 @@ runTest("2011-11-08 19:48:43.100", "2011-11-08T19:48:43.100");
runTest("2011-11-08 19:48:43.1000", "2011-11-08T19:48:43.100");
runTest("2011-11-08 19:48:43.12345", "2011-11-08T19:48:43.123");
// previously the '+' or '-' would be skipped and the offset interpreted as a time
runTest("2011-11-08+01:00", null);
runTest("2011-11-08-01:00", null);
function runTest(dateToTest, isoDate)
{
if (isoDate === null) {

0 comments on commit ffebc17

Please sign in to comment.