From d8b14f94e7ab4228c54370c183ef265824b41287 Mon Sep 17 00:00:00 2001 From: Sage Gerard Date: Fri, 1 Dec 2017 00:38:49 -0500 Subject: [PATCH] fix: allow null config values (#108) --- index.js | 2 +- test/yargs-parser.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c06d9370..1a2c7cb5 100644 --- a/index.js +++ b/index.js @@ -479,7 +479,7 @@ function parse (args, opts) { // if the value is an inner object and we have dot-notation // enabled, treat inner objects in config the same as // heavily nested dot notations (foo.bar.apple). - if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) { + if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) { // if the value is an object but not an array, check nested object setConfigObject(value, fullKey) } else { diff --git a/test/yargs-parser.js b/test/yargs-parser.js index d2d56545..0c9bb97c 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -642,13 +642,15 @@ describe('yargs-parser', function () { configObjects: [{ apple: 'apple', banana: 42, - foo: 'baz' + foo: 'baz', + gotcha: null }] }) argv.should.have.property('apple', 'apple') argv.should.have.property('banana', 42) argv.should.have.property('foo', 'bar') + argv.should.have.property('gotcha', null) }) it('should use value from config object, if argv value is using default value', function () {