From 8188682d3dba499944bbd8657e95d5b7a81ef0d8 Mon Sep 17 00:00:00 2001 From: not-an-aardvark Date: Thu, 12 May 2016 16:11:49 -0400 Subject: [PATCH] Use Object.create(null) for the config object --- src/default_config.js | 8 ++++++-- src/snoowrap.js | 2 +- test/snoowrap.spec.js | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/default_config.js b/src/default_config.js index f4d183e3..fbdd5248 100644 --- a/src/default_config.js +++ b/src/default_config.js @@ -1,5 +1,7 @@ +import {assign} from 'lodash'; // Defines the default config values. For more information on these, see the documentation for snoowrap#config() -export default { +const config = Object.create(null); +assign(config, { endpoint_domain: 'reddit.com', request_delay: 0, request_timeout: 30000, @@ -8,4 +10,6 @@ export default { max_retry_attempts: 3, warnings: true, debug: false -}; +}); + +export default config; diff --git a/src/snoowrap.js b/src/snoowrap.js index b964e3fc..601f9ebc 100644 --- a/src/snoowrap.js +++ b/src/snoowrap.js @@ -97,7 +97,7 @@ const snoowrap = class { * // sets the request delay to 1000 milliseconds, and suppresses warnings. */ config (options) { - const invalid_key = findKey(options, (value, key) => !this._config.hasOwnProperty(key)); + const invalid_key = findKey(options, (value, key) => !Object.prototype.hasOwnProperty.call(this._config, key)); if (invalid_key) { throw new TypeError(`Invalid config option '${invalid_key}'`); } diff --git a/test/snoowrap.spec.js b/test/snoowrap.spec.js index e3fbcf21..44a285c1 100644 --- a/test/snoowrap.spec.js +++ b/test/snoowrap.spec.js @@ -124,6 +124,9 @@ describe('snoowrap', function () { it('throws a TypeError if an invalid config option is set', () => { expect(() => r.config({invalid_config_option: true})).to.throw(TypeError); }); + it('does not use Object.prototype for the config object', () => { + expect(Object.getPrototypeOf(r.config())).to.be.null(); + }); it('sets all prototype functions as non-enumerable', () => { const ensure_prototype_funcs_arent_enumerable = obj => { Object.getOwnPropertyNames(obj.prototype).forEach(funcName => {