Skip to content
Myr

fix(param): Decode context.param (#662)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Decode url param * Denoify

authored by Jayden · committed by GitHub · parent ce31e2a · Browse files · 4 files+23 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+23 added−5 removed

  • tests:+6 added−0 removed
  • other:+17 added−5 removed

4 files+23 added−5 removed

modified:deno_dist/utils/encode.ts+1 added-1 removed
modified:deno_dist/request.ts+8 added-2 removed
54 unmodified lines
5556 Request.prototype.param = function (this: Request, key?: string) {57 if (this.paramData) {58 if (key) {59 return this.paramData[key]59 return decodeURIComponent(this.paramData[key])60 } else {61 return this.paramData61 const decoded: Record<string, string> = {}6263 for (const [key, value] of Object.entries(this.paramData)) {64 decoded[key] = decodeURIComponent(value)65 }6667 return decoded68 }69 }70 return null71 } as InstanceType<typeof Request>['param']
99 unmodified lines
modified:src/hono.test.ts+6 added
324 unmodified lines
325 expect(res.status).toBe(200)326 expect(await res.text()).toBe('id is 123')327 })328329 it('param of /entry/:id is decoded', async () => {330 const res = await app.request('http://localhost/entry/%C3%A7awa%20y%C3%AE%3F')331 expect(res.status).toBe(200)332 expect(await res.text()).toBe('id is çawa yî?')333 })334335 it('param of /date/:date is found', async () => {336 const res = await app.request('http://localhost/date/0401')337 expect(res.status).toBe(200)338 expect(await res.text()).toBe('date is 0401')
1010 unmodified lines
modified:src/request.ts+8 added-2 removed
54 unmodified lines
5556 Request.prototype.param = function (this: Request, key?: string) {57 if (this.paramData) {58 if (key) {59 return this.paramData[key]59 return decodeURIComponent(this.paramData[key])60 } else {61 return this.paramData61 const decoded: Record<string, string> = {}6263 for (const [key, value] of Object.entries(this.paramData)) {64 decoded[key] = decodeURIComponent(value)65 }6667 return decoded68 }69 }70 return null71 } as InstanceType<typeof Request>['param']
99 unmodified lines