From: Mark Stosberg Date: Thu, 13 Oct 2016 21:04:54 +0000 (-0400) Subject: Fix #3500: ISO 8601 parsing should match the full string, not the beginning of the... X-Git-Tag: 2.16.0~16^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=945985998ce3b83f3cd675925bfb93b1b3bb9e14;p=thirdparty%2Fmoment.git Fix #3500: ISO 8601 parsing should match the full string, not the beginning of the string. 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. --- diff --git a/src/lib/create/from-string.js b/src/lib/create/from-string.js index 0c86761a3..63df05ea8 100644 --- a/src/lib/create/from-string.js +++ b/src/lib/create/from-string.js @@ -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)?/; diff --git a/src/test/moment/create.js b/src/test/moment/create.js index 9c509f0fd..549b3c941 100644 --- a/src/test/moment/create.js +++ b/src/test/moment/create.js @@ -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) {