]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Fix the escape problem of analytic regex (#4631)
authorAlanscut <wp_scut@163.com>
Wed, 29 Apr 2020 01:20:09 +0000 (09:20 +0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 29 Apr 2020 21:54:17 +0000 (00:54 +0300)
src/lib/units/day-of-week.js
src/test/moment/is_valid.js

index 125a43e7b5d0d40fa9a39960891ee14ad9d7ba8b..73adf82bf36e53f9939aec25222c83b3d9cfd5c2 100644 (file)
@@ -408,9 +408,9 @@ function computeWeekdaysParse() {
     for (i = 0; i < 7; i++) {
         // make the regex if we don't have it already
         mom = createUTC([2000, 1]).day(i);
-        minp = this.weekdaysMin(mom, '');
-        shortp = this.weekdaysShort(mom, '');
-        longp = this.weekdays(mom, '');
+        minp = regexEscape(this.weekdaysMin(mom, ''));
+        shortp = regexEscape(this.weekdaysShort(mom, ''));
+        longp = regexEscape(this.weekdays(mom, ''));
         minPieces.push(minp);
         shortPieces.push(shortp);
         longPieces.push(longp);
@@ -424,11 +424,6 @@ function computeWeekdaysParse() {
     shortPieces.sort(cmpLenRev);
     longPieces.sort(cmpLenRev);
     mixedPieces.sort(cmpLenRev);
-    for (i = 0; i < 7; i++) {
-        shortPieces[i] = regexEscape(shortPieces[i]);
-        longPieces[i] = regexEscape(longPieces[i]);
-        mixedPieces[i] = regexEscape(mixedPieces[i]);
-    }
 
     this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
     this._weekdaysShortRegex = this._weekdaysRegex;
index d97972600d95b24dd34ea854eb233b515a68e999..6da3823030e5a0742a3ac79c2b2e3b7b4f430e24 100644 (file)
@@ -524,3 +524,40 @@ test('0 hour is invalid in strict', function (assert) {
         '0 hour is valid in normal'
     );
 });
+
+test('format locale', function (assert) {
+    var a = [
+            ['uto 15.05.2018', 'dd DD.MM.YYYY', 'bs'],
+            ['dt 15.05.2018', 'dd DD.MM.YYYY', 'ca'],
+            ['Di 15.05.2018', 'dd DD.MM.YYYY', 'de-dt'],
+            ['Di 15.05.2018', 'dd DD.MM.YYYY', 'de'],
+            ['mar 15.05.2018', 'dd DD.MM.YYYY', 'es-do'],
+            ['mar 15.05.2018', 'dd DD.MM.YYYY', 'es-us'],
+            ['Di 15.05.2018', 'dd DD.MM.YYYY', 'es'],
+            ['ar 15.05.2018', 'dd DD.MM.YYYY', 'eu'],
+            ['mar 15.05.2018', 'dd DD.MM.YYYY', 'fr-ca'],
+            ['mar 15.05.2018', 'dd DD.MM.YYYY', 'fr-ch'],
+            ['mar 15.05.2018', 'dd DD.MM.YYYY', 'fr'],
+            ['ti 15.05.2018', 'dd DD.MM.YYYY', 'fy'],
+            ['mar 15.05.2018', 'dd DD.MM.YYYY', 'gl'],
+            ['मंगळ 15.05.2018', 'dd DD.MM.YYYY', 'gom-deva'],
+            ['Mon 15.05.2018', 'dd DD.MM.YYYY', 'gom-latn'],
+            ['uto 15.05.2018', 'dd DD.MM.YYYY', 'hr'],
+            ['Dë 15.05.2018', 'dd DD.MM.YYYY', 'lb'],
+            ['uto 15.05.2018', 'dd DD.MM.YYYY', 'me'],
+            ['ti 15.05.2018', 'dd DD.MM.YYYY', 'nb'],
+            ['मङ्गल 15.05.2018', 'dd DD.MM.YYYY', 'ne'],
+            ['di 15.05.2018', 'dd DD.MM.YYYY', 'nl-be'],
+            ['di 15.05.2018', 'dd DD.MM.YYYY', 'nl'],
+            ['ty 15.05.2018', 'dd DD.MM.YYYY', 'nn'],
+            ['dm 15.05.2018', 'dd DD.MM.YYYY', 'oc-lnc'],
+            ['tor 15.05.2018', 'dd DD.MM.YYYY', 'sl'],
+            ['уто 15.05.2018', 'dd DD.MM.YYYY', 'sr-cyrl'],
+            ['uto 15.05.2018', 'dd DD.MM.YYYY', 'sr'],
+            ['uto 15.05.2018', 'dd DD.MM.YYYY', 'sr'],
+        ],
+        i;
+    for (i = 0; i < a.length; i++) {
+        assert.ok(moment(a[i][0], a[i][1], a[i][2]).isValid());
+    }
+});