fix(filter): reject unknown filter operators instead of silently dropping the filter#283
Open
SAY-5 wants to merge 1 commit intoblnkfinance:mainfrom
Open
fix(filter): reject unknown filter operators instead of silently dropping the filter#283SAY-5 wants to merge 1 commit intoblnkfinance:mainfrom
SAY-5 wants to merge 1 commit intoblnkfinance:mainfrom
Conversation
…ping the filter Previously, when a request body included a filter with an unrecognized operator (e.g. `equals` instead of `eq`), `Validate` did not check the per-filter operator and `buildStandardCondition` fell through to its `default` branch, returning an empty condition string. The caller then skipped that condition entirely, leaving the query unfiltered. Endpoints that fetch the first matching row would happily return whatever row they saw first, making the response look successful even though the user's filter was never applied. This adds: - `IsValidOperator` in `internal/filter/operators.go`, the operator-side counterpart to the existing `IsValidLogicalOperator`. - A check in `Validate` that rejects unknown operators with a descriptive error listing the supported operators. - Tests covering the unknown-operator and empty-operator cases on both `Validate` and `Build`, including a regression note tied to the reported issue. Closes blnkfinance#282
Collaborator
|
Thank you for the PR @SAY-5 |
Collaborator
hi @SAY-5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #282.
When a JSON request body specifies a filter with an unrecognized operator
(e.g.
\"equals\"instead of\"eq\"), the filter package was silentlydropping that filter and running the query unfiltered. Endpoints that
return the first matching row therefore looked successful even though the
user's filter never reached the database.
The reproduction in the issue is exactly this:
{ \"filters\": [ { \"field\": \"meta_data.name\", \"operator\": \"equals\", \"value\": \"...\" } ] }The body parses successfully (operator is just a string),
Validatechecks logical_operator and field but not the per-filter operator, and
buildStandardConditionfalls through itsdefaultbranch returning anempty condition.
Buildskips empty conditions, so the resulting SQL hasno WHERE clause for that filter — the API returns the first row it finds
with no error.
Fix
IsValidOperatorininternal/filter/operators.go, theoperator-side counterpart to the existing
IsValidLogicalOperator.Validatewith a descriptive error thatlists the supported operators (
eq,ne,gt,gte,lt,lte,in,between,like,ilike,isnull,isnotnull).400 Bad Requestfrom any endpoint that callsBuild/BuildWithOptions, matching the existing handling of invalidfields and invalid logical operators.
The fix is minimal and additive — no signatures changed, no behavior
changes for valid operators, no new error categories.
Test plan
\"equals\") and emptyoperator on both `Validate` and `Build`.
tests fail with the silent-drop behavior the issue describes.