Repository navigation
fix(model): read the sort direction in an order string whatever its case - #4346
Merged
Merged
Conversation
$orderByClause() checked for " ASC" / " DESC" with case-sensitive Find(),
so a lowercase direction was missed and " ASC" was appended:
order="id desc" sorted ascending, and a "table.column desc" item became
"table.column desc ASC" and threw Wheels.InvalidOrderClause. The query
builder's orderBy("id", "desc") reached the same code.
Each order item now goes through $normalizeOrderItem(): whitespace runs
(spaces, tabs) collapse to one space, a trailing asc/desc is read in any
case and emitted in upper case, and an item without one sorts ascending.
The query builder stores the direction in upper case too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Peter Amiri <peter@alurium.com>
Collaborator
Author
Review @ 2938265: source looks good. Final verdict after matrix 37328749853 and PR CIWhat was wrong
The fix
Spec (
No findings. On the matrix I'll read |
Contributor
Wheels Test Results222 804 tests 217 683 ✅ 1h 24m 8s ⏱️ Results for commit 2938265. |
Collaborator
Author
Final: APPROVE @ 2938265 (matrix 37328749853, all 32 legs read; PR CI read)Matrix
PR CI: 17 pass, 3 skipping, 0 fail, 0 pending. The |
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
findAll(order="createdAt desc")sorted ascending.$orderByClause()looked for the direction with case-sensitiveFind(" ASC")/Find(" DESC"), so a lowercase or mixed-case direction wasn't seen and" ASC"was appended (model/sql.cfm:262).The same parser serves all the paths below, so the fix covers each of them:
findAll()/findOne():order="id desc"sorted ascending.findAll(page=..., perPage=...)): the same.table.column descitem: it becametable.column desc ASCand threwWheels.InvalidOrderClause, because the dot-notation check is also case-sensitive.orderBy("id", "desc"): it validated the direction case-insensitively and then built"id desc", so it too sorted ascending.Change
vendor/wheels/model/sql.cfm: each order item goes through a new$normalizeOrderItem().asc/descis read in any case and emitted in upper case.$orderByClause()is unchanged. The dot-notation check and SQL Server's paginated ORDER BY reversal then always see an upper-case direction.vendor/wheels/model/query/QueryBuilder.cfc:orderBy()stores the direction in upper case.read.cfm:90(ReplaceNoCase) and the adapter's$columnAlias()(CFML==is case-insensitive) were already case-insensitive.fixedfragment.Tests
New
vendor/wheels/tests/specs/model/orderDirectionCaseSpec.cfc:desc/Desc/dEsC/DESCall sort descending;asc/Asc/ASCand no direction all sort ascending;lastName asc, id descmatches the uppercase form;table.column descitem;orderBy("id", "desc").RED (develop, Lucee 7 + SQLite): 4 failed and 1 errored. Lowercase sorts ascending in the plain, whitespace, paginated and query-builder cases, and the
table.column desccase errors withInvalid dot-notation in ORDER BY clause.GREEN,
modeldirectory (pass / fail / error;orderDirectionCaseSpec7/7 on every leg):internalspecs: 113 passed.modeldirectory: 1395 / 0 / 0, with the new spec 7/7.🤖 Generated with Claude Code