Skip to content

Relative assign with eval unexpectedly creates new keys #2558

@kknicker

Description

@kknicker

I have created a YAML "!eval" tag to evaluate embedded yq expressions.

yq '. ref $root | (.. | select(tag == "!eval")) |= (. tag = "" | . as $expr | $root | eval($expr))' t.yaml
x: 1
y: 2
z: !eval .x + .y
x: 1
y: 2
z: 3

If the expression consists of undefined values sometimes the value is unchanged.

x: 1
y: 2
z: !eval .a + .b
x: 1
y: 2
z: .a + .b

In other cases the value is null, but also results in new keys being created for the undefined values.

x: 1
y: 2
z: !eval .a * .b
x: 1
y: 2
z: null
a: null
b: null

I am guessing this has something to do with the expression being evaluated to null versus something else.

I'm not sure if this is a bug, but it seems wrong that it would create new keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions