Skip to content

Commit ffebc17

Browse files
committed
[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
2 parents 3ee8aca + 05dda62 commit ffebc17

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/Runtime/Library/DateImplementation.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,19 +1118,13 @@ namespace Js {
11181118
continue;
11191119
}
11201120
case '+':
1121-
{
1122-
if (lwNil != lwTime)
1123-
{
1124-
ss = ssAddOffset;
1125-
}
1126-
continue;
1127-
}
11281121
case '-':
11291122
{
1130-
if (lwNil != lwTime)
1123+
if (lwNil == lwTime)
11311124
{
1132-
ss = ssSubOffset;
1125+
goto LError;
11331126
}
1127+
ss = (ch == '+') ? ssAddOffset : ssSubOffset;
11341128
continue;
11351129
}
11361130
}
@@ -1300,7 +1294,7 @@ namespace Js {
13001294
{
13011295
AssertMsg(isNextFieldDateNegativeVersion5 == false, "isNextFieldDateNegativeVersion5 == false");
13021296

1303-
if (lwNil != lwOffset)
1297+
if (lwNil != lwOffset || lwNil == lwTime)
13041298
goto LError;
13051299
// convert into minutes, e.g. 730 -> 7*60+30
13061300
lwOffset = lwT < 24 ? lwT * 60 :

test/Date/DateParse3.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ runTest("2011-11-08 19:48:43.100", "2011-11-08T19:48:43.100");
2424
runTest("2011-11-08 19:48:43.1000", "2011-11-08T19:48:43.100");
2525
runTest("2011-11-08 19:48:43.12345", "2011-11-08T19:48:43.123");
2626

27+
// previously the '+' or '-' would be skipped and the offset interpreted as a time
28+
runTest("2011-11-08+01:00", null);
29+
runTest("2011-11-08-01:00", null);
30+
2731
function runTest(dateToTest, isoDate)
2832
{
2933
if (isoDate === null) {

0 commit comments

Comments
 (0)