Allow an empty string as an is filter value - #95
Merged
Merged
Conversation
`KnexAdapter` declares `filter:is` and `filter:is not` as `.empty(['null', ''])`, so an empty string was always meant to coerce to `null`. The filter parser rejected it first, though, because Joi's `string()` disallows an empty string by default — making that half of the adapter rule unreachable and erroring on `?filter[x][is]=`, which is a natural way for a client to ask for `is null`. Deferring to the adapter costs nothing elsewhere, since every other operator rejects an empty string through its own schema. The eleven comparison and `like` operators return a byte-identical message one layer later, and the four array operators now say "must be an array", which is already what they say for every other scalar. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
KnexAdapterdeclaresfilter:isandfilter:is notas.empty(['null', '']), so an empty string was always meant to coerce tonull. The filterparser rejected it first, though, because Joi's
string()disallows an emptystring by default — making that half of the adapter rule unreachable and
erroring on
?filter[x][is]=, which is a natural way for a client to ask foris null. Only the'null'string worked.Deferring the decision to the adapter costs nothing elsewhere, because every
other operator rejects an empty string through its own schema. Measured across
all seventeen:
is,is notis null/is not null=!=<>>>=<<=likenot likeilikenot ilikeinnot inbetweennot betweenThe existing
permits an empty string valuetests in the adapter suite passedagainst the broken pipeline because they call
validateValuedirectly andskip the parser, so the regression tests here are an end-to-end assertion
through
run()plus a parser-level one.🤖 Generated with Claude Code