Skip to content

Commit

Permalink
fix: tolerate null prototype for config objects with extends (#1376)
Browse files Browse the repository at this point in the history
Fixes #1372
  • Loading branch information
coreyfarrell authored and bcoe committed Jul 23, 2019
1 parent 015eeb9 commit 3d26d11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/apply-extends.js
Expand Up @@ -19,7 +19,7 @@ function getPathToDefaultConfig (cwd, pathToExtend) {
function applyExtends (config, cwd) {
let defaultConfig = {}

if (config.hasOwnProperty('extends')) {
if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
if (typeof config.extends !== 'string') return defaultConfig
const isPath = /\.json|\..*rc$/.test(config.extends)
let pathToDefault = null
Expand Down
14 changes: 14 additions & 0 deletions test/yargs.js
Expand Up @@ -1292,6 +1292,20 @@ describe('yargs dsl tests', () => {
argv.z.should.equal(15)
})

it('tolerates null prototype config objects', () => {
const argv = yargs
.config({
__proto__: null,
a: 2,
extends: './test/fixtures/extends/config_1.json'
})
.parse()

argv.a.should.equal(2)
argv.b.should.equal(22)
argv.z.should.equal(15)
})

// see: https://www.npmjs.com/package/yargs-test-extends
it('allows a module to be extended, rather than a JSON file', () => {
const argv = yargs()
Expand Down

0 comments on commit 3d26d11

Please sign in to comment.