Skip to content

Strange behavior of // operator since 4.45.3 #2377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lbilger opened this issue May 19, 2025 · 0 comments
Open

Strange behavior of // operator since 4.45.3 #2377

lbilger opened this issue May 19, 2025 · 0 comments
Labels

Comments

@lbilger
Copy link

lbilger commented May 19, 2025

Describe the bug
It seems that the behavior of the // operator has changed between 4.45.2 and 4.45.3. I have been wondering why my expression failed with the newer version (I upgraded from 4.45.1 to 4.45.4) and tried around a lot. This is what I found.

Version of yq: 4.45.3 and 4.45.4
Operating system: Mac
Installed via: brew and docker

Input Yaml
data.yml

- foo: false

Command
The command you ran:

yq -o json  '.[] | (select(.foo) | {"foo": .foo} // {})' data.yml

Actual behavior

no output

Expected behavior

{}

Additional context
I wrote the following script to test this on multiple versions easily:

#!/usr/bin/env bash

test_data='
- foo: false
'

for version in 4.45.1 4.45.2 4.45.3; do
  for command in '.[] | (select(.foo) | {"foo": .foo} // {})' '.[] | (select(.foo) | {.foo} // {})'; do
    echo ${version} "${command}"
    echo -------
    echo "${test_data}" | podman run -i --rm  mikefarah/yq:${version} -o json "${command}"
    echo -------
    echo
  done
done

Note that '.[] | (select(.foo) | {.foo} // {})' yields a result in all versions, but '.[] | (select(.foo) | {"foo": .foo} // {})' doesn't in versions 4.45.3 onwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant