Skip to content

fix(handler): preserve request order for repeated query-string params - #138

Merged
zmstone merged 1 commit into
emqx:masterfrom
zmstone:260805-qs-array-param-order
Aug 6, 2026
Merged

fix(handler): preserve request order for repeated query-string params#138
zmstone merged 1 commit into
emqx:masterfrom
zmstone:260805-qs-array-param-order

Conversation

@zmstone

@zmstone zmstone commented Aug 5, 2026

Copy link
Copy Markdown
Member

Root cause

minirest_handler:parse_qs/1 folds over cowboy_req:parse_qs/1 (which yields pairs in request order) with lists:foldl while prepending each repeated value, so multi-value query parameters reached handlers in reverse request order: /qs_params?array=foo&array=bar arrived as [<<"bar">>, <<"foo">>].

Fix

Fold with lists:foldr instead. The last occurrence is seen first (stored as the scalar), and each earlier occurrence prepends in front of it, yielding request order. Single-occurrence params are unchanged (still a bare scalar, not a list); valueless flags (?footrue) are unchanged as well.

Behavior change

This is an observable ordering change for any consumer of multi-value query params: they now arrive in request order instead of reversed. The reversed order was an undocumented fold accident, and no known consumer relies on it. Known consumers want request order — emqx/emqx#18267 promises "results in query-parameter order" for GET /clients?clientid=a&clientid=b, and the order-sensitive tests in emqx/emqx#18268 tripped over the reversal. The existing t_qs_params test asserted the reversed order; it is flipped and strengthened to three occurrences.

Follow-ups (not in this PR)

  • Tag the next minirest release and bump the pin in emqx.git (currently 1.4.12).

@zmstone
zmstone merged commit b714f0b into emqx:master Aug 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants