From 0b542302de05e5080eed2b9203cee7659fb3cdef Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Thu, 7 Sep 2023 16:10:43 +0100 Subject: [PATCH 1/2] Fix special characters encoding in query string --- package-lock.json | 14 +++++++------- package.json | 2 +- src/parameters.ts | 17 +++-------------- tests/integration/parameters.test.ts | 2 +- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 482c53e..09c5c99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@asteasolutions/zod-to-openapi": "^5.3.1", - "itty-router": "^4.0.14", + "itty-router": "^4.0.22", "openapi3-ts": "^4.1.2", "zod": "^3.21.4" }, @@ -4190,9 +4190,9 @@ } }, "node_modules/itty-router": { - "version": "4.0.14", - "resolved": "https://registry.npmjs.org/itty-router/-/itty-router-4.0.14.tgz", - "integrity": "sha512-s8DfaLkQp+E3kBhjwto3Z91ozulotCLAmlS8AIr230NqwFJssiGIoewo1P+CEkZ3YrzghS9k/RVvmMlvKQxueQ==" + "version": "4.0.22", + "resolved": "https://registry.npmjs.org/itty-router/-/itty-router-4.0.22.tgz", + "integrity": "sha512-FWK13vcITqld32NaOh+k2unRrR4qBZdzA9O1ctpqT1Q4lxKrHbtgaX1lLTv2VyXj3/8Waqk/NlDGNfxypJ8GKA==" }, "node_modules/jest": { "version": "29.0.0", @@ -10738,9 +10738,9 @@ } }, "itty-router": { - "version": "4.0.14", - "resolved": "https://registry.npmjs.org/itty-router/-/itty-router-4.0.14.tgz", - "integrity": "sha512-s8DfaLkQp+E3kBhjwto3Z91ozulotCLAmlS8AIr230NqwFJssiGIoewo1P+CEkZ3YrzghS9k/RVvmMlvKQxueQ==" + "version": "4.0.22", + "resolved": "https://registry.npmjs.org/itty-router/-/itty-router-4.0.22.tgz", + "integrity": "sha512-FWK13vcITqld32NaOh+k2unRrR4qBZdzA9O1ctpqT1Q4lxKrHbtgaX1lLTv2VyXj3/8Waqk/NlDGNfxypJ8GKA==" }, "jest": { "version": "29.0.0", diff --git a/package.json b/package.json index 0f48ad6..821d14b 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ }, "dependencies": { "@asteasolutions/zod-to-openapi": "^5.3.1", - "itty-router": "^4.0.14", + "itty-router": "^4.0.22", "openapi3-ts": "^4.1.2", "zod": "^3.21.4" } diff --git a/src/parameters.ts b/src/parameters.ts index 7412acc..1deba0d 100644 --- a/src/parameters.ts +++ b/src/parameters.ts @@ -293,25 +293,14 @@ export function extractQueryParameters( request: Request, schema?: ZodObject ): Record | null { - const url = decodeURIComponent(request.url).split('?') + const { searchParams } = new URL(request.url) - if (url.length === 1) { + if (searchParams.size === 0) { return null } - let query = url.slice(1).join('?') - - // RFC 3986 allows query string to start with & - if (query.startsWith('&')) { - query = query.substring(1) - } - const params: Record = {} - for (const param of query.split('&')) { - const paramSplit = param.split('=') - const key = paramSplit[0] - const value = paramSplit[1] - + for (const [key, value] of searchParams.entries()) { if (params[key] === undefined) { params[key] = value } else if (!Array.isArray(params[key])) { diff --git a/tests/integration/parameters.test.ts b/tests/integration/parameters.test.ts index 0e992b0..04ea0c6 100644 --- a/tests/integration/parameters.test.ts +++ b/tests/integration/parameters.test.ts @@ -258,7 +258,7 @@ describe('queryParametersValidation', () => { }) test('checkRegexValid', async () => { - const qs = '?p_regex=+919367788755' + const qs = '?p_regex=%2B919367788755' const request = await todoRouter.handle( buildRequest({ method: 'GET', path: `/todos${qs}` }) ) From 44ad01dca02df5f17a8ebb307d81b3dbcb92b293 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Thu, 7 Sep 2023 16:34:41 +0100 Subject: [PATCH 2/2] Update github actions --- .github/workflows/create-pullrequest-prerelease.yml | 4 ++-- .github/workflows/publish.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/create-pullrequest-prerelease.yml b/.github/workflows/create-pullrequest-prerelease.yml index 7bbb8b9..c89a570 100644 --- a/.github/workflows/create-pullrequest-prerelease.yml +++ b/.github/workflows/create-pullrequest-prerelease.yml @@ -14,10 +14,10 @@ jobs: with: fetch-depth: 0 - - name: Use Node.js 16.13 + - name: Use Node.js 20.6 uses: actions/setup-node@v3 with: - node-version: 16.13 + node-version: 20.6 cache: 'npm' # cache ~/.npm in case 'npm ci' needs to run - name: Set RELEASE_VERSION diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ecac8b9..8ff6139 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,7 @@ jobs: - name: Setup .npmrc file to publish to npm uses: actions/setup-node@v1 with: - node-version: '16.x' + node-version: '20.x' registry-url: 'https://registry.npmjs.org' - name: Set RELEASE_VERSION run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 504fbac..c911c02 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: matrix: os: - ubuntu-latest - node: [14.x, 16.x, 18.x] + node: [18.x, 20.x] steps: - uses: actions/checkout@v2