]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix #3500: ISO 8601 parsing should match the full string, not the beginning of the...
authorMark Stosberg <mark@rideamigos.com>
Thu, 13 Oct 2016 21:04:54 +0000 (17:04 -0400)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 6 Nov 2016 09:37:33 +0000 (01:37 -0800)
Because of the nature of the how related tests are put together, the newly added test
*passes* even before the fix is applied.

This happens because the "non-ISO" tests are tested against the same ISO which is being fixed.

Because the broken regex is also used in the test, it allowed the non ISO date to be validated
before the fix.

src/lib/create/from-string.js
src/test/moment/create.js

index 0c86761a3539863fa8ba60d0b522819dae118a78..63df05ea8dab7c074acfac01575771d9bc3b5941 100644 (file)
@@ -5,8 +5,8 @@ import getParsingFlags from './parsing-flags';
 
 // iso 8601 regex
 // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
-var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
-var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
+var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
+var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
 
 var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
 
index 9c509f0fd63d5230cc9d38ac544611f59e2c6d39..549b3c941ddaa0f6ee64a2d42083998be73203f9 100644 (file)
@@ -634,6 +634,7 @@ test('non iso 8601 strings', function (assert) {
     assert.ok(!moment('2015W10T1015', moment.ISO_8601, true).isValid(), 'incomplete week date with time (basic)');
     assert.ok(!moment('2015-10-08T1015', moment.ISO_8601, true).isValid(), 'mixing extended and basic format');
     assert.ok(!moment('20151008T10:15', moment.ISO_8601, true).isValid(), 'mixing basic and extended format');
+    assert.ok(!moment('2015-10-1', moment.ISO_8601, true).isValid(), 'missing zero padding for day');
 });
 
 test('parsing iso week year/week/weekday', function (assert) {