Skip to content

Commit

Permalink
Use Object.create(null) for the config object
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed May 12, 2016
1 parent f1bfa5b commit 8188682
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/default_config.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -8,4 +10,6 @@ export default {
max_retry_attempts: 3,
warnings: true,
debug: false
};
});

export default config;
2 changes: 1 addition & 1 deletion src/snoowrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`);
}
Expand Down
3 changes: 3 additions & 0 deletions test/snoowrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 8188682

Please sign in to comment.