Skip to content

Commit

Permalink
fix(lookup): don't parse nested array elements as string templates
Browse files Browse the repository at this point in the history
When parsing nested arrays in the lookup function, pass all values
through the lookup parser instead of just object types and handling the
rest as if they are string templates.

Signed-off-by: Jacob Hull <[email protected]>
  • Loading branch information
jakedipity committed Mar 22, 2024
1 parent 40d9c18 commit f25f5cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ module.exports = class SetupChain {
// remap array values with lookup result
if (Array.isArray(value)) {
out[key] = value.map((val) => {
if (typeOf(val) === 'object') return this.lookup(val)
const resolved = this[lookup](this.parse(val))
return resolved
return this.lookup(val)
})
continue
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ test('chain', async (t) => {
t.same(chain.lookup(lookup), expected, 'can populate an array')
}

{
const expected = {position: [11, 2]}
const lookup = {position: [11, 2]}
t.same(chain.lookup(lookup), expected, 'array values parse number literals')
}

{
const expected = {key: 11, values: [2, 10, {foo: 3}]}
const lookup = {key: '#g', values: ['#b.c', '#f', {foo: '#b.d.e'}]}
Expand Down

0 comments on commit f25f5cd

Please sign in to comment.