Skip to content

Commit 4969148

Browse files
AVaksmanstephenplusplus
authored andcommitted
fix: do not modify constructor options (#974)
1 parent 388e32d commit 4969148

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/storage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,14 @@ export class Storage extends Service {
372372
* @param {StorageOptions} [options] Configuration options.
373373
*/
374374
constructor(options: StorageOptions = {}) {
375-
options.apiEndpoint = options.apiEndpoint || 'storage.googleapis.com';
375+
options = Object.assign({}, options, {
376+
apiEndpoint: options.apiEndpoint || 'storage.googleapis.com',
377+
});
376378
const url =
377379
process.env.STORAGE_EMULATOR_HOST ||
378380
`https://${options.apiEndpoint}/storage/v1`;
379381
const config = {
380-
apiEndpoint: options.apiEndpoint,
382+
apiEndpoint: options.apiEndpoint!,
381383
baseUrl: url,
382384
projectIdRequired: false,
383385
scopes: [

test/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ describe('Storage', () => {
141141
);
142142
});
143143

144+
it('should not modify options argument', () => {
145+
const options = {
146+
projectId: PROJECT_ID,
147+
};
148+
const expectedCalledWith = Object.assign({}, options, {
149+
apiEndpoint: 'storage.googleapis.com',
150+
});
151+
storage = new Storage(options);
152+
const calledWith = storage.calledWith_[1];
153+
assert.notStrictEqual(calledWith, options);
154+
assert.notDeepStrictEqual(calledWith, options);
155+
assert.deepStrictEqual(calledWith, expectedCalledWith);
156+
});
157+
144158
it('should propagate the apiEndpoint option', () => {
145159
const apiEndpoint = 'some.fake.endpoint';
146160
storage = new Storage({

0 commit comments

Comments
 (0)