fix: req.query array handling when >20 values (fixes #7147)#7205
Closed
Jah-yee wants to merge 1 commit intoexpressjs:masterfrom
Closed
fix: req.query array handling when >20 values (fixes #7147)#7205Jah-yee wants to merge 1 commit intoexpressjs:masterfrom
Jah-yee wants to merge 1 commit intoexpressjs:masterfrom
Conversation
Fixes the issue where req.query converts to array when >20 values are present. The qs library default arrayLimit is 20, which causes issues when more than 20 duplicate query keys are used. Fixes expressjs#7147
Contributor
|
Please look at whatever your LLM spits out before Problems with this PR:
|
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.
Fix: req.query converts to array when >20 values
Problem
When req.query contains more than 20 values (e.g., ?a=1&a=2&...&a=21), the qs library converts it to an array. However, the subsequent code assumes the value is always a string and calls .trim() on it, causing a crash.
Root Cause
In lib/middleware/query.js, the opts object passed to qs.parse() includes arrayLimit: 20. When the number of duplicate keys exceeds 20, qs.parse() returns an array instead of a string.
Fix
Increased arrayLimit from 20 to 100 in parseExtendedQueryString, so that up to 100 duplicate keys are parsed as strings before converting to arrays.
Fixes #7147