Skip to content

Commit

Permalink
fix bug in !$merge: !$ tags in the input not being processed
Browse files Browse the repository at this point in the history
  • Loading branch information
tavisrudd committed Nov 29, 2019
1 parent 6db516b commit 4ed9a1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/preprocess/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class Visitor {
}

visit$merge(node: yaml.$merge, path: string, env: Env): AnyButUndefined[] {
const input: any = _.isString(node.data) ? this.visit$include(new yaml.$include(node.data), path, env) : node.data;
const input: any = _.isString(node.data) ? this.visit$include(new yaml.$include(node.data), path, env) : this.visitNode(node.data, path, env);
if (!_.isArray(input) && _.every(input, _.isObject)) {
throw new Error(`Invalid argument to $merge at "${path}".`
+ " Must be array of arrays.");
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test-yaml-preprocessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,28 @@ m: !$merge
`)).to.deep.equal({m: result});
});

it('with a list of maps with first item being an include', async () => {
expect(await transform(`
$defs:
map1: ${JSON.stringify(map1)}
m: !$merge
- !$ map1
- ${JSON.stringify(map2)}
- ${JSON.stringify(map3)}
`)).to.deep.equal({m: result});
});

it('with a list of maps with last item being an include', async () => {
expect(await transform(`
$defs:
map3: ${JSON.stringify(map3)}
m: !$merge
- ${JSON.stringify(map1)}
- ${JSON.stringify(map2)}
- !$ map3
`)).to.deep.equal({m: result});
});

it('with a string argument referring to a variable', async () => {
expect(await transform(`
$defs:
Expand Down

0 comments on commit 4ed9a1f

Please sign in to comment.