Skip to content

Commit

Permalink
Don't freeze any other values than plain objects and arrays (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak authored and sindresorhus committed Aug 23, 2018
1 parent a7cd35a commit 2ffcd49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/deep-freeze.js
Expand Up @@ -3,7 +3,7 @@ const is = require('@sindresorhus/is');

module.exports = function deepFreeze(object) {
for (const [key, value] of Object.entries(object)) {
if (is.object(value)) {
if (is.plainObject(value) || is.array(value)) {
deepFreeze(object[key]);
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/create.js
@@ -1,3 +1,4 @@
import http from 'http';
import {URL} from 'url';
import test from 'ava';
import got from '../source';
Expand Down Expand Up @@ -145,6 +146,14 @@ test('no tampering with defaults', t => {
t.is(instance2.defaults.options.baseUrl, 'example');
});

test('only plain objects are freezed', async t => {
const instance = got.extend({
agent: new http.Agent({keepAlive: true})
});

await t.notThrowsAsync(() => instance(s.url));
});

test('defaults are cloned on instance creation', t => {
const options = {foo: 'bar', hooks: {beforeRequest: [() => {}]}};
const instance = got.create({options});
Expand Down

0 comments on commit 2ffcd49

Please sign in to comment.