Skip to content

Commit be76ee6

Browse files
authored
fix: address pkgConf parsing bug outlined in #37 (#45)
1 parent 487fecf commit be76ee6

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ function parse (args, opts) {
351351

352352
// Set normalized value when key is in 'normalize' and in 'arrays'
353353
if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
354-
value = path.normalize(val)
354+
if (Array.isArray(val)) value = val.map(path.normalize)
355+
else value = path.normalize(val)
355356
}
356357

357358
var splitKey = key.split('.')

test/yargs-parser.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,4 +2025,14 @@ describe('yargs-parser', function () {
20252025
parsed.error.message.should.equal('banana')
20262026
})
20272027
})
2028+
2029+
// see: https://github.com/yargs/yargs-parser/issues/37
2030+
it('normalizes all paths in array when provided via config object', function () {
2031+
var argv = parser([ '--foo', 'bar' ], {
2032+
array: ['a'],
2033+
normalize: ['a'],
2034+
configObjects: [{'a': ['bin/../a.txt', 'bin/../b.txt']}]
2035+
})
2036+
argv.a.should.deep.equal(['a.txt', 'b.txt'])
2037+
})
20282038
})

0 commit comments

Comments
 (0)