From e36a60693b584779b93ebe1ca9efde56f0a3dd2a Mon Sep 17 00:00:00 2001 From: Phil DeJarnett Date: Wed, 19 Nov 2014 16:34:01 -0500 Subject: [PATCH] Cloned input arrays to prevent modification of passed-in values, found by @Peter-Donner. Fixes #18 --- index.js | 5 ++++- test/main.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a46d513..c5e7fb0 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,10 @@ function verifyTaskSets(gulp, taskSets, skipArrays) { } function runSequence(gulp) { - var taskSets = Array.prototype.slice.call(arguments, 1), + // Slice and dice the input to prevent modification of parallel arrays. + var taskSets = Array.prototype.slice.call(arguments, 1).map(function(task) { + return Array.isArray(task) ? task.slice() : task; + }), callBack = typeof taskSets[taskSets.length-1] === 'function' ? taskSets.pop() : false, currentTaskSet, diff --git a/test/main.js b/test/main.js index b91f5d8..b238dcc 100644 --- a/test/main.js +++ b/test/main.js @@ -74,6 +74,14 @@ describe('runSequence', function() { }) }); + describe('Input Array Handling', function() { + it('should not modify passed-in parallel task arrays', function() { + var taskArray = ['task1', 'task2']; + runSequence(taskArray); + taskArray.should.eql(['task1', 'task2']); + }); + }); + describe('Asynchronous Tasks', function() { it('should run a single task', function() { task1.shouldPause = true;