fix: apply sort request for columns marked sortable after list construction - #6589
Merged
Conversation
…uction Since the sort column is validated against the sortable columns (GHSA-4f5f-j737-pm58), sorting via column headers stopped working: the query runs in the rex_list constructor, but setColumnSortable() is called afterwards, so the whitelist was always empty at that point. When a sort request is pending, the constructor now fetches only the field names (via a free LIMIT 0 metadata query) and defers the data query to get(), where all sortable columns are registered (including those added via the REX_LIST_GET extension point).
Contributor
|
Danke @gharlan <3 |
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 #6585
Problem
Since the sort column is validated against the sortable columns (GHSA-4f5f-j737-pm58, #6580), sorting via column headers stopped working: the query runs in the
rex_listconstructor, butsetColumnSortable()is called afterwards, so the whitelist was always empty at the timeprepareQuery()built theORDER BY.Solution
When a sort request is pending (
listparam matches andsortparam present), the constructor no longer loads the data. It fetches only the field names via aLIMIT 0metadata query (optimized away by MySQL, needed forgetColumnNames()/addColumn()etc.) and defers the data query toget()— at that point all sortable columns are registered, including those added via theREX_LIST_GETextension point.LIMIT 0metadata + one data query with the validatedORDER BY.getRows()/getValue()lazily trigger the initial data load in case they are used beforeget();get()re-executes only if the effective query changed in the meantime.Note: existing
rex_listbehavior is unchanged in that a query with a hardcodedORDER BY(and no$defaultSort) still ignores sort requests — use the$defaultSortfactory parameter instead.Verified end-to-end in the backend (users list, cronjobs list with temporarily enabled sortable columns): default sort, asc/desc via column headers, and rejected non-sortable columns.