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
func TestXPathName(t *testing.T) {
doc, err := jsonquery.Parse(strings.NewReader(`{
"Reviews": {
"A Tale of Two Cities": "Not Bad"
},
"Books": [
{
"Title": "Of Mice and Men",
"Price": 11
},
{
"Title": "A Tale of Two Cities",
"Price": 10
}
]
}`,
))
assert.NoError(t, err)
currentBookPrice, err := jsonquery.Query(doc, `/Books/*[Title=name(/Reviews/*)]/Price`)
assert.NoError(t, err)
assert.NotNil(t, currentBookPrice)
}
Explanation
When running the query the filter evaluates it's expression multiple times. However the name() function always runs Select(t) on the same query. Because query's contain their own iterator the first time the name function is evaluated it returns the name of the first match, and the second time it returns the second match. This can be demonstrated in the example by removing "Of Mice and Men" from the JSON document which will allow the test to pass.
Suggestion
I admit I don't fully understand the expression logic, but it seems as like when a function like name calls Select(t) on its argument it should call Clone() first to avoid using the same iterator.
The text was updated successfully, but these errors were encountered:
Test Case
Explanation
When running the query the filter evaluates it's expression multiple times. However the
name()
function always runsSelect(t)
on the same query. Because query's contain their own iterator the first time the name function is evaluated it returns the name of the first match, and the second time it returns the second match. This can be demonstrated in the example by removing "Of Mice and Men" from the JSON document which will allow the test to pass.Suggestion
I admit I don't fully understand the expression logic, but it seems as like when a function like
name
callsSelect(t)
on its argument it should callClone()
first to avoid using the same iterator.The text was updated successfully, but these errors were encountered: