We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
Array subtraction appears to modify its LHS. When the LHS is a variable that is used again later, this has unexpected results.
Version of yq:
$ yq --version yq (https://github.com/mikefarah/yq/) version v4.44.3
Operating system: macOS Installed via: homebrew
Input Yaml
["a", "b"]
Command The command you ran:
$ <<<'["a", "b"]' yq e '["a","b"] as $f | {"0": $f, "1": $f - ., "2": $f}'
Actual behavior
The variable appears to be modified. .2 is empty.
.2
"0": - a - b "1": [] "2": []
Expected behavior
.2 should contain the assigned value of $f, ["a", "b"]
$f
Compare to re-using a variable without doing the array subtraction:
$ <<<'["a", "b"]' yq e '["a","b"] as $f | {"0": $f, "2": $f}' "0": - a - b "2": - a - b
If the LHS is the context ., the same thing occurs:
.
$ <<<'["a", "b"]' yq e '["a","b"] as $f | {"0": ., "1": . - $f, "2": .}' "0": ["a", "b"] "1": [] "2": []
As a point of comparison, jq does not have this behavior:
$ <<<'["a", "b"]' jq '["a","b"] as $f | {"0": $f, "1": ($f - .) , "2": $f}' { "0": [ "a", "b" ], "1": [], "2": [ "a", "b" ] }
Additional context
I think this is due to this line: https://github.com/mikefarah/yq/blob/master/pkg/yqlib/operator_subtract.go#L41
// removing children from LHS, parent hasn't changed lhs.Content = newLHSArray
I don't understand the intent expressed by the comment.
The text was updated successfully, but these errors were encountered:
Thanks for raising, will fix in the next release
Sorry, something went wrong.
Fixed array subtraction update bug #2159
f654fbf
No branches or pull requests
Describe the bug
Array subtraction appears to modify its LHS. When the LHS is a variable that is used again later, this has unexpected results.
Version of yq:
Operating system: macOS
Installed via: homebrew
Input Yaml
["a", "b"]
Command
The command you ran:
Actual behavior
The variable appears to be modified.
.2
is empty.Expected behavior
.2
should contain the assigned value of$f
,["a", "b"]
Compare to re-using a variable without doing the array subtraction:
If the LHS is the context
.
, the same thing occurs:As a point of comparison, jq does not have this behavior:
Additional context
I think this is due to this line:
https://github.com/mikefarah/yq/blob/master/pkg/yqlib/operator_subtract.go#L41
I don't understand the intent expressed by the comment.
The text was updated successfully, but these errors were encountered: