From be76ee6e602bd2ff3541763c54aba834a3b9ef8c Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 8 Aug 2016 21:40:00 -0700 Subject: [PATCH] fix: address pkgConf parsing bug outlined in #37 (#45) --- index.js | 3 ++- test/yargs-parser.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3ac52af2..90f24ad2 100644 --- a/index.js +++ b/index.js @@ -351,7 +351,8 @@ function parse (args, opts) { // Set normalized value when key is in 'normalize' and in 'arrays' if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) { - value = path.normalize(val) + if (Array.isArray(val)) value = val.map(path.normalize) + else value = path.normalize(val) } var splitKey = key.split('.') diff --git a/test/yargs-parser.js b/test/yargs-parser.js index d2f82b4f..5eee105a 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -2025,4 +2025,14 @@ describe('yargs-parser', function () { parsed.error.message.should.equal('banana') }) }) + + // see: https://github.com/yargs/yargs-parser/issues/37 + it('normalizes all paths in array when provided via config object', function () { + var argv = parser([ '--foo', 'bar' ], { + array: ['a'], + normalize: ['a'], + configObjects: [{'a': ['bin/../a.txt', 'bin/../b.txt']}] + }) + argv.a.should.deep.equal(['a.txt', 'b.txt']) + }) })