Open
Description
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.