Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special characters encoding in query string #95

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/create-pullrequest-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
17 changes: 3 additions & 14 deletions src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,25 +293,14 @@ export function extractQueryParameters(
request: Request,
schema?: ZodObject<any>
): Record<string, any> | 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<string, any> = {}
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])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` })
)
Expand Down
Loading