]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Avoid mutating the passed array on initialization 505/head
authorIvan Krechetov <ivan.krechetov@gmail.com>
Sat, 10 Nov 2012 11:07:09 +0000 (12:07 +0100)
committerIvan Krechetov <ivan.krechetov@gmail.com>
Sat, 10 Nov 2012 11:07:09 +0000 (12:07 +0100)
moment.js
test/moment/create.js

index 87123e3f6599e68770eb82b016ccfe67a652772f..12ae51f485870f504f36980ccc5e3940bb7168e1 100644 (file)
--- a/moment.js
+++ b/moment.js
         } else if (typeof input === 'string') {
             makeDateFromString(config);
         } else if (isArray(input)) {
-            config._a = input;
+            config._a = input.slice(0);
             dateFromArray(config);
         } else {
             config._d = input instanceof Date ? input : new Date(input);
index 099ef018b53a4dc87f06360b190541c92a31ffd4..41defc75304deea8ba91155ce5a837007ee4c207 100644 (file)
@@ -14,6 +14,14 @@ exports.create = {
         test.done();
     },
 
+    "array copying": function(test) {
+        var importantArray = [2009, 11];
+        test.expect(1);
+        moment(importantArray);
+        test.deepEqual(importantArray, [2009, 11], "initializer should not mutate the original array");
+        test.done();
+    },
+
     "number" : function(test) {
         test.expect(3);
         test.ok(moment(1000).toDate() instanceof Date, "1000");