Repository navigation
fix: several bugs found while writing the docs - #57
Merged
Merged
Conversation
`getIterator()` only applied the result modifier, so `readonly()` was a no-op for direct iteration (it worked via `first()`/`take()`/`eager()`).
`count()` memoizes, but `__clone()` only cloned the query builder - so every derived result inherited the original's count.
`%` and `_` in a `contains()`/`startsWith()`/`endsWith()` value were passed through to the LIKE pattern, where they acted as wildcards. They're now escaped via an ESCAPE clause, leaving `*` as the only wildcard.
… `Criteria` The guard tested `$this->inner instanceof Criteria`, which is never true, so passing a `Criteria` to a non-`Selectable` collection threw `InvalidSpecification` instead of explaining the real problem.
The callback can modify the `Criteria` directly, but returning it (as `andWhere()` does) made `transform()` violate its own return type.
Covers literal `%`/`_` in LIKE specifications, `readonly()` when iterating, and modifying the `Criteria` from `Spec::callback()`.
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.
Fixes the bugs found while writing the README (#3), each with tests that fail without the fix.
readonly()was a no-op when iterating anEntityResult.getIterator()applied only the result modifier, notnormalizeResult()- so entities were detached viafirst()/take()/eager()but not viaforeach.LIKEvalues weren't escaped.str_replace('%', '%%')isn't SQL escaping: the value is a bound parameter, so%and_reached the database as wildcards (Spec::contains('value', '%')matched every row). They're now escaped with anESCAPEclause, leaving*as the only wildcard.DoctrineBridgeCollection::filter()checked the wrong variable ($this->inner instanceof Criteriarather than$specification), making theLogicExceptionunreachable and surfacing a confusingInvalidSpecificationinstead.EntityResult::count()memoization survived cloning, so every derived result inherited the original's count.CriteriaInterpreterdidn't guard theSpec::callback()return value. Returning theCriteria(asandWhere()does) violatedtransform()'s own return type. The callback may now either modify theCriteriaor return anExpression; both are tested. This also adds the first coverage forSpec::callback().The last commit documents the behavior these change.
Note: making
_literal is technically a behavior change for anyone relying on it as a single-character wildcard - it was undocumented and almost certainly unintended.