Skip to content

Commit

Permalink
Do not mutate user-supplied opts (stripe#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcheung-stripe authored Oct 14, 2020
1 parent 54c99ed commit bbefa30
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const utils = (module.exports = {
if (typeof arg === 'string') {
opts.auth = args.pop();
} else if (utils.isOptionsHash(arg)) {
const params = args.pop();
const params = {...args.pop()};

const extraKeys = Object.keys(params).filter(
(key) => !OPTIONS_KEYS.includes(key)
Expand Down
29 changes: 29 additions & 0 deletions test/makeRequest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

require('../testUtils');

const makeRequest = require('../lib/makeRequest');
const expect = require('chai').expect;

describe('makeRequest', () => {
describe('args', () => {
it('does not mutate user-supplied deprecated opts', () => {
const args = [
{
stripe_account: 'bad',
},
];
const mockSelf = {
createResourcePathWithSymbols: () => {},
createFullPath: () => {},
_request: () => {},
};
makeRequest(mockSelf, args, {}, {});
expect(args).to.deep.equal([
{
stripe_account: 'bad',
},
]);
});
});
});

0 comments on commit bbefa30

Please sign in to comment.