Fix/enable case insensitive queries #15127
Closed
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
In NestJS v11, after the upgrade to Express 5.x, the req.query property became a read-only getter. This broke any middleware or logic that attempted to modify req.query to normalize query parameter keys (e.g., to make them case-insensitive). Currently, there is no built-in way to enable case-insensitive query handling in the @nestjs/platform-express package, and attempting to modify req.query directly results in a TypeError: Cannot set property query of # which has only a getter
Issue Number: #15115
What is the new behavior?
This PR introduces a new method enableCaseInsensitiveQueries to the ExpressAdapter class in the @nestjs/platform-express package. The method adds a middleware that normalizes all query parameter keys to lowercase, ensuring case-insensitive handling of query parameters. Key features of the new behavior include:
Does this PR introduce a breaking change?
Other information
Case-Insensitive Query Parameters
Starting with NestJS v11, you can enable case-insensitive query parameter handling in applications using the
@nestjs/platform-express
package. This feature normalizes all query parameter keys to lowercase, allowing controllers to access parameters consistently regardless of the case used in the request URL.To enable this feature, call the
enableCaseInsensitiveQueries
method on your application instance:Example
With case-insensitive queries enabled, a request to /test?NAME=John&AGE=30 will be processed as if the parameters were name=John and age=30. A controller can then access these parameters without worrying about the case:
This feature also supports nested objects and arrays in query parameters, ensuring consistent normalization across all keys.
This PR closes issue #15115 by addressing the Express 5.x compatibility issue and providing a new feature for case-insensitive query handling.