`req.params` includes port number, regression `0.35.0`-`0.36.0`
See original GitHub issueDescribe the bug
When upgrading msw@0.35.0
to latest I noticed one of my utility method started to fail. I narrowed this issue to msw@0.36.0
.
Some background. Not necessary for the bug but gives some insight.
I have a utility method which validates that all req.params
values are encrypted. I have a specific pattern which can be utilized to identify such fields. For now lets call this pattern /somepattern/
.
function validateQueryParametersAreEncrypted(request) {
Object.entries(request.params).forEach(([name, value]) => {
if (!/somepattern/.test(value)) {
throw new Error(`URL parameter (${name}) was not encrypted: (${value})`);
}
});
}
This validation is applied to all my MSW handlers. It is now failing due to :3000
not matching /somepattern/
.
Environment
msw: 0.36.3
nodejs: 16.13.1
npm: 8.3.0
Please also provide your browser version.
Google Chrome 96
To Reproduce
Steps to reproduce the behavior:
- Setup https://github.com/mswjs/examples/tree/master/examples/rest-react
- Add new handler:
rest.get("/example/:id", (req, res, ctx) => {
console.log("req.params", req.params);
return res(ctx.status(200));
})
- Add new request:
fetch("/example/someid");
.
Expected behavior
Below is logs from different MSW versions. Version 0.35.0
works as expected.
rest.get("/example/:id", (req, res, ctx) => {
console.log("req.params", req.params);
// ^^ msw@0.35.0 req.params {id: 'someid'}
// ^^ msw@0.36.0 req.params {3000: ':3000', id: 'someid'}
// ^^ msw@0.36.1 req.params {3000: ':3000', id: 'someid'}
// ^^ msw@0.36.2 req.params {3000: ':3000', id: 'someid'}
// ^^ msw@0.36.3 req.params {3000: ':3000', id: 'someid'}
return res(ctx.status(200));
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Express.js req.params Property - GeeksforGeeks
The req. params property is an object containing properties mapped to the named route “parameters”. For example, if you have the route /student ......
Read more >Why does req.params return an empty array? - Stack Overflow
req.params only contain the route params, not query string params (from GET) and not body params (from POST). The param() function however checks...
Read more >What is req.params in Express.js? - Educative.io
req.params is an object of the req object that contains route parameters. If the params are specified when a URL is built, then...
Read more >How To Retrieve URL and POST Parameters with Express
req.params can be used to retrieve values from routes. Consider the following URL: http://localhost:8080/api/1. This URL includes routes for ...
Read more >Node and Express for Beginners - James Q Quick
We are defining the path for this route to include the id as a query parameter. Here's the code. app.get("/books/:id", (req, res) =>...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was comparing the bundled
coercePath
and the one from source, and was able to find the likely root cause. It seemsmain
branch contains unreleased changes which might have fixed these, https://github.com/mswjs/msw/pull/1028 (👋 @tdeekens).Below is comparison between
0.36.3
andmain
.coercePath msw@0.36.3
coercePath msw@main, unreleased
So it seems
coercePath
will be buggy in releases0.36.0 - 0.36.3
only. Once new version is released I can do the final verification.Fix verified with version
0.36.4
- port number is no longer included in thereq.params
. Thanks!