You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The slice array operator does not work as expected when used after an expression.
Since ["cat", "dog", "frog", "cow"][1] evaluates to "dog",
I would expect ["cat", "dog", "frog", "cow"][1:] to evaluate to ["dog", "frog", "cow"].
But it acts as .[1:] was written and returns the slice of the input.
An error is returned in the case of the "without the first number" array slice.
yq should give an error in both cases or, better yet, support both. In the first case, it's a bug to accept the syntax and ignore the left hand side. In the second case, the error message is not intuitive.
Error: '' expects 2 args but there is 1
Error: '|' expects 2 args but there is 1
Expected behavior
- cat
- dog
- cat
- dog
Additional context .b[1:] acts similarly, as does $arr[1:].
Once you are aware of this bug, you can work around it by moving the expression to input and using a dot, .[n:m]. E.g. instead of ["cat", "dog", "frog", "cow"][1:] write ["cat", "dog", "frog", "cow"] | .[1:]
but until then it's a head scratcher for either of the cases.
Describe the bug
The slice array operator does not work as expected when used after an expression.
Since
["cat", "dog", "frog", "cow"][1]
evaluates to"dog"
,I would expect
["cat", "dog", "frog", "cow"][1:]
to evaluate to["dog", "frog", "cow"]
.But it acts as
.[1:]
was written and returns the slice of the input.An error is returned in the case of the "without the first number" array slice.
yq
should give an error in both cases or, better yet, support both. In the first case, it's a bug to accept the syntax and ignore the left hand side. In the second case, the error message is not intuitive.Version of yq: 4.45.1
Operating system: ubuntu
Installed via: direct download from https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_amd64
Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
data1.yml:
Command
The command you ran:
Actual behavior
Expected behavior
Command
The command you ran:
Actual behavior
- 'entry 2'
Expected behavior
- dog
Command
The command you ran:
Actual behavior
Expected behavior
Additional context
.b[1:]
acts similarly, as does$arr[1:]
.Once you are aware of this bug, you can work around it by moving the expression to input and using a dot,
.[n:m]
. E.g. instead of["cat", "dog", "frog", "cow"][1:]
write["cat", "dog", "frog", "cow"] | .[1:]
but until then it's a head scratcher for either of the cases.
Ref: Slice array man page: https://mikefarah.gitbook.io/yq/operators/slice-array
The text was updated successfully, but these errors were encountered: