From bbefa309039eae38fc221601e539ac838f6f0890 Mon Sep 17 00:00:00 2001 From: vcheung-stripe <71457708+vcheung-stripe@users.noreply.github.com> Date: Wed, 14 Oct 2020 07:00:28 -0700 Subject: [PATCH] Do not mutate user-supplied opts (#1041) --- lib/utils.js | 2 +- test/makeRequest.spec.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/makeRequest.spec.js diff --git a/lib/utils.js b/lib/utils.js index 16c9f95be6..5bca895adf 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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) diff --git a/test/makeRequest.spec.js b/test/makeRequest.spec.js new file mode 100644 index 0000000000..93fe5e67f1 --- /dev/null +++ b/test/makeRequest.spec.js @@ -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', + }, + ]); + }); + }); +});