Skip to content

Commit 93eb416

Browse files
authored
Fix special characters encoding in query string (cloudflare#95)
1 parent e96d903 commit 93eb416

File tree

7 files changed

+16
-27
lines changed

7 files changed

+16
-27
lines changed

.github/workflows/create-pullrequest-prerelease.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
with:
1515
fetch-depth: 0
1616

17-
- name: Use Node.js 16.13
17+
- name: Use Node.js 20.6
1818
uses: actions/setup-node@v3
1919
with:
20-
node-version: 16.13
20+
node-version: 20.6
2121
cache: 'npm' # cache ~/.npm in case 'npm ci' needs to run
2222

2323
- name: Set RELEASE_VERSION

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup .npmrc file to publish to npm
1414
uses: actions/setup-node@v1
1515
with:
16-
node-version: '16.x'
16+
node-version: '20.x'
1717
registry-url: 'https://registry.npmjs.org'
1818
- name: Set RELEASE_VERSION
1919
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
matrix:
2424
os:
2525
- ubuntu-latest
26-
node: [14.x, 16.x, 18.x]
26+
node: [18.x, 20.x]
2727

2828
steps:
2929
- uses: actions/checkout@v2

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
},
9393
"dependencies": {
9494
"@asteasolutions/zod-to-openapi": "^5.3.1",
95-
"itty-router": "^4.0.14",
95+
"itty-router": "^4.0.22",
9696
"openapi3-ts": "^4.1.2",
9797
"zod": "^3.21.4"
9898
}

src/parameters.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,25 +293,14 @@ export function extractQueryParameters(
293293
request: Request,
294294
schema?: ZodObject<any>
295295
): Record<string, any> | null {
296-
const url = decodeURIComponent(request.url).split('?')
296+
const { searchParams } = new URL(request.url)
297297

298-
if (url.length === 1) {
298+
if (searchParams.size === 0) {
299299
return null
300300
}
301301

302-
let query = url.slice(1).join('?')
303-
304-
// RFC 3986 allows query string to start with &
305-
if (query.startsWith('&')) {
306-
query = query.substring(1)
307-
}
308-
309302
const params: Record<string, any> = {}
310-
for (const param of query.split('&')) {
311-
const paramSplit = param.split('=')
312-
const key = paramSplit[0]
313-
const value = paramSplit[1]
314-
303+
for (const [key, value] of searchParams.entries()) {
315304
if (params[key] === undefined) {
316305
params[key] = value
317306
} else if (!Array.isArray(params[key])) {

tests/integration/parameters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ describe('queryParametersValidation', () => {
258258
})
259259

260260
test('checkRegexValid', async () => {
261-
const qs = '?p_regex=+919367788755'
261+
const qs = '?p_regex=%2B919367788755'
262262
const request = await todoRouter.handle(
263263
buildRequest({ method: 'GET', path: `/todos${qs}` })
264264
)

0 commit comments

Comments
 (0)