From 7192497e69a38e2915c84b1a4b7f80551e3e99f9 Mon Sep 17 00:00:00 2001 From: Taku Amano Date: Fri, 17 May 2024 06:03:36 +0900 Subject: [PATCH] refactor: Stop decoding URIs in the `param()` method, since they are already decoded in `getPath()` --- src/request.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/request.ts b/src/request.ts index 7c028aee5..4a8ffa6b2 100644 --- a/src/request.ts +++ b/src/request.ts @@ -12,7 +12,7 @@ import type { import { parseBody } from './utils/body' import type { BodyData, ParseBodyOptions } from './utils/body' import type { UnionToIntersection } from './utils/types' -import { getQueryParam, getQueryParams, decodeURIComponent_ } from './utils/url' +import { getQueryParam, getQueryParams } from './utils/url' type Body = { json: any @@ -82,28 +82,26 @@ export class HonoRequest

{ param(key: string): string | undefined param(): UnionToIntersection>> param(key?: string): unknown { - return key ? this.getDecodedParam(key) : this.getAllDecodedParams() + return key ? this.getParam(key) : this.getAllDecodedParams() } - private getDecodedParam(key: string): string | undefined { + private getParam(key: string): string | undefined { const paramKey = this.#matchResult[0][this.routeIndex][1][key] - const param = this.getParamValue(paramKey) - - return param ? (/\%/.test(param) ? decodeURIComponent_(param) : param) : undefined + return this.getParamValue(paramKey) } private getAllDecodedParams(): Record { - const decoded: Record = {} + const params: Record = {} const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]) for (const key of keys) { const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]) if (value && typeof value === 'string') { - decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value + params[key] = value } } - return decoded + return params } private getParamValue(paramKey: any): string | undefined {