Skip to content
New issue

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

fix: Change how we index the filter operations before evaluation #124

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/ffapi/restfilter_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ func (jq *QueryJSON) addSimpleFilters(ctx context.Context, fb FilterBuilder, jso
func joinShortNames(long, short, negated []*FilterJSONKeyValue) []*FilterJSONKeyValue {
res := make([]*FilterJSONKeyValue, len(long)+len(short)+len(negated))
copy(res, long)
copy(res[len(short):], short)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
copy(res[len(short):], short)
copy(res[len(long):], short)

Isn't this the bug @SamMayWork ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if there were a problem with copy having nil as the right parameter, then that would be a problem in the line above, which this PR doesn't change)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep after making the change from short -> long the surrounding if block is actually redundant now, removing now 🖊️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 066994c


if len(long) == 0 {
copy(res[0:], short)
} else {
copy(res[len(long):], short)
}

negs := res[len(short)+len(long):]
copy(negs, negated)
for _, n := range negs {
Expand Down
47 changes: 47 additions & 0 deletions pkg/ffapi/restfilter_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,50 @@ func TestBuildQueryJSONBadFields(t *testing.T) {
func TestBuildQueryJSONDocumented(t *testing.T) {
CheckObjectDocumented(&QueryJSON{})
}

func TestBuildQueryJSONContainsShortNames(t *testing.T) {

var qf1 QueryJSON
err := json.Unmarshal([]byte(`{
"eq": [
{
"field": "sequence",
"value": "12345"
}
]
}`), &qf1)
assert.NoError(t, err)

filter, err := qf1.BuildFilter(context.Background(), TestQueryFactory)
assert.NoError(t, err)

fi, err := filter.Finalize()
assert.NoError(t, err)

assert.Equal(t, "sequence == 12345", fi.String())

var qf2 QueryJSON
err = json.Unmarshal([]byte(`{
"gt": [
{
"field": "sequence",
"value": "12345"
}
],
"lte": [
{
"field": "sequence",
"value": "12345"
}
]
}`), &qf2)
assert.NoError(t, err)

filter, err = qf2.BuildFilter(context.Background(), TestQueryFactory)
assert.NoError(t, err)

fi, err = filter.Finalize()
assert.NoError(t, err)

assert.Equal(t, "( sequence <= 12345 ) && ( sequence >> 12345 )", fi.String())
}
Loading