]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix moment().locale('ivalid-id') 1896/head
authorIskren Chernev <iskren.chernev@gmail.com>
Fri, 29 Aug 2014 16:11:45 +0000 (19:11 +0300)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 5 Sep 2014 04:42:35 +0000 (21:42 -0700)
moment.js
test/moment/locale.js

index 868206aadfba8555ad22a6522ecc9517ee7bcba6..3b5d65adc3185d0104ffe0b6e4d0ae3673d0f1d1 100644 (file)
--- a/moment.js
+++ b/moment.js
         // instance.  Otherwise, it will return the locale configuration
         // variables for this instance.
         locale : function (key) {
+            var newLocaleData;
+
             if (key === undefined) {
                 return this._locale._abbr;
             } else {
-                this._locale = moment.localeData(key);
+                newLocaleData = moment.localeData(key);
+                if (newLocaleData != null) {
+                    this._locale = newLocaleData;
+                }
                 return this;
             }
         },
                 if (key === undefined) {
                     return this.localeData();
                 } else {
-                    this._locale = moment.localeData(key);
-                    return this;
+                    return this.locale(key);
                 }
             }
         ),
index bf0bcdefbc1235ee2607758643b73af7419e13ff..57ecb4ae9d9d39bb2a9338f94aafa1b58866797e 100644 (file)
@@ -458,5 +458,17 @@ exports.locale = {
         test.equal(m.locale(), 'fr', 'instance locale reset to global locale');
 
         test.done();
+    },
+
+    'moment().locale with missing key doesn\'t change locale' : function (test) {
+        test.equal(moment().locale('boo').localeData(), moment.localeData(),
+                'preserve global locale in case of bad locale id');
+        test.done();
+    },
+
+    'moment().lang with missing key doesn\'t change locale' : function (test) {
+        test.equal(moment().lang('boo').localeData(), moment.localeData(),
+                'preserve global locale in case of bad locale id');
+        test.done();
     }
 };