Skip to content

select does not eliminate all mismatches #2422

@davidBGraham66

Description

@davidBGraham66

the select function passes through objects that it should filter out

input:

{ "project":{ "channels":[
{ "cName":"c1", "cVal":"North" },
{ "cName":"c2", "cVal":"North" },
{ "cName":"c3", "cVal":"South" },
{ "cName":"c4", "cVal":"North" },
{ "cName":"c5", "cVal":"South" }
] } }

code:

.project.channels[] |= select( ."cVal" == "South")

expected ouput:
{
"project": {
"channels": [
{
"cName": "c3",
"cVal": "South"
},
{
"cName": "c5",
"cVal": "South"
}
]
}
}

actual output
{
"project": {
"channels": [
{
"cName": "c2",
"cVal": "North"
},
{
"cName": "c3",
"cVal": "South"
},
{
"cName": "c5",
"cVal": "South"
}
]
}
}

select failed to eliminate all objects where cVal was not "South"

The behavior seems to be that , if there are two objects in a row that need eliminated, it lets the second one pass .
This could happen if the code was traversing a linked list, testing each node, eliminating a node, then going to next node.
If the code eliminates a node, then the following node will become the current node, so the code should then test the (new) current node before moving on.

The behavior is seen on jqplay.org

(
and also on jq-win64.exe with proper windows quoting

jq-Win64.exe ".project.channels[] |= select( ."""cVal""" == """South""") " my.txt

)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions