From: Ivan Krechetov Date: Sat, 10 Nov 2012 11:07:09 +0000 (+0100) Subject: Avoid mutating the passed array on initialization X-Git-Tag: 2.0.0~39^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F505%2Fhead;p=thirdparty%2Fmoment.git Avoid mutating the passed array on initialization --- diff --git a/moment.js b/moment.js index 87123e3f6..12ae51f48 100644 --- a/moment.js +++ b/moment.js @@ -806,7 +806,7 @@ } 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); diff --git a/test/moment/create.js b/test/moment/create.js index 099ef018b..41defc753 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -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");