Permalink
Browse files

Change Date.parse() to require a time component when using an offset.

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.
  • Loading branch information...
mlfaw committed Nov 5, 2018
1 parent 3ee8aca commit f48516c6f92d98c39f2dc9a4f95c554d63dc8c38
Showing with 6 additions and 10 deletions.
  1. +4 −10 lib/Runtime/Library/DateImplementation.cpp
  2. +2 −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 :
@@ -24,6 +24,8 @@ 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");
runTest("2011-11-08+01:00", null); // previously the '+' or '-' would be skipped and the offset interpreted as a time
function runTest(dateToTest, isoDate)
{
if (isoDate === null) {

0 comments on commit f48516c

Please sign in to comment.