8000 fix!: Avoid modifying arguments (#21) · gulpjs/plugin-error@6c05aba · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c05aba

Browse files
authored
fix!: Avoid modifying arguments (#21)
1 parent 334c165 commit 6c05aba

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,12 @@ function setDefaults(plugin, message, opts) {
164164
if (typeof plugin === 'object') {
165165
return defaults(plugin);
166166
}
167-
opts = opts || {};
168167
if (message instanceof Error) {
169-
opts.error = message;
168+
opts = Object.assign({}, opts, { error: message });
170169
} else if (typeof message === 'object') {
171-
opts = message;
170+
opts = Object.assign({}, message);
172171
} else {
173-
opts.message = message;
172+
opts = Object.assign({}, opts, { message: message });
174173
}
175174
opts.plugin = plugin;
176175
return defaults(opts);

test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,18 @@ describe('PluginError()', function () {
251251
expect(err.toString().indexOf('Details:')).toEqual(-1);
252252
done();
253253
});
254+
255+
it('should not modify error argument', function(done) {
256+
var realErr = { message: 'something broke' };
257+
new PluginError('test', realErr);
258+
expect(realErr).toEqual({ message: 'something broke' });
259+
done();
260+
});
261+
262+
it('should not modify options argument', function(done) {
263+
var opts = { showStack: true };
264+
new PluginError('test', 'message', opts);
265+
expect(opts).toEqual({ showStack: true });
266+
done();
267+
});
254268
});

0 commit comments

Comments
 (0)
0