Skip to content

Commit ca10cf5

Browse files
authored
QueryString.parse is legacy, upgraded to newer recommendations
1 parent 43c2672 commit ca10cf5

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Converts request body to string.
7979

8080
### `urlencoded(req, res, cb)`
8181

82-
Parses request body using `querystring.parse`.
82+
Parses request body using `new URLSearchParams`.
8383

8484
### `json(req, res, cb)`
8585

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export default [
1414
{
1515
input: 'src/index.ts',
1616
...common,
17-
external: ['querystring', 'http'],
17+
external: ['http'],
1818
},
1919
]

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ServerResponse as Response, IncomingMessage, STATUS_CODES } from 'http'
2-
import * as qs from 'querystring'
32
import { EventEmitter } from 'events'
43

54
type NextFunction = (err?: any) => void
@@ -54,7 +53,10 @@ const text = () => async (req: ReqWithBody, _res: Response, next: NextFunction)
5453

5554
const urlencoded = () => async (req: ReqWithBody, res: Response, next: NextFunction) => {
5655
if (hasBody(req.method)) {
57-
req.body = await p((x) => qs.parse(x.toString()))(req, res, next)
56+
req.body = await p((x) => {
57+
const urlSearchParam = new URLSearchParams(x.toString());
58+
return Object.fromEntries(urlSearchParam.entries())
59+
})(req, res, next)
5860
next()
5961
} else next()
6062
}

0 commit comments

Comments
 (0)