Skip to content

Traversing map with complex key does not work as it should #2403

Open
@stevenwdv

Description

@stevenwdv

Describe the bug
Traversing a map with complex keys does not work as it should.
E.g. overriding a map key with an alias key and then traversing gives the wrong value.
And keys may match when they should not.

Version of yq: 4.45.4
Operating system: linux
Installed via: binary release

Commands

# Alias key does not overwrite
echo '{k: &k a, a: 1, *k : 2}' | yq '.a'
#Actual: 1
#Expected: 2

# Complex keys are all treated the same
echo '{["I am not the key you are looking for"]: 42}' | yq '.[{"wait": "what"}]'
#Actual: 42
#Expected: null

# And a merge anchor test for when the case above is fixed
echo '{m: &m {v: 37}, {v: 37}: 1, {<<: *m}: 2, [idk]: 3}' | yq '.[{"v": 37}]'
#Actual: 3
#Expected: 2

Additional context
For alias keys (the first test case), explode(.).a does work as expected (returns 2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions