Skip to content
Myr

Merge commit from fork

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

authored by Taku Amano · committed by GitHub · parent c831020 · Browse files · 2 files+35 added−1 removed
This commit

State

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

Diff stats

2 files+35 added−1 removed

  • tests:+34 added−0 removed
  • other:+1 added−1 removed

2 files+35 added−1 removed

modified:src/hono-base.ts+1 added-1 removed
362 unmodified lines
363 const mergedPath = mergePath(this._basePath, path)364 const pathPrefixLength = mergedPath === '/' ? 0 : mergedPath.length365 return (request) => {366 const url = new URL(request.url)367 url.pathname = url.pathname.slice(pathPrefixLength) || '/'367 url.pathname = this.getPath(request).slice(pathPrefixLength) || '/'368 return new Request(url, request)369 }370 })()371
174 unmodified lines
modified:src/hono.test.ts+34 added
2683 unmodified lines
2684 expect(await res.text()).toBe('AnotherApp')2685 })2686 })26872688 describe('With encoded paths', () => {2689 const anotherApp = (req: Request) => new Response(getPath(req))26902691 it('Should strip a decoded non-ASCII mount prefix', async () => {2692 const app = new Hono()2693 app.mount('/api/é', anotherApp)26942695 const res = await app.request('/api/%C3%A9/hello')26962697 expect(res.status).toBe(200)2698 expect(await res.text()).toBe('/hello')2699 })27002701 it('Should preserve an encoded slash as a literal path segment after stripping the prefix', async () => {2702 const app = new Hono()2703 app.mount('/api/v1', anotherApp)27042705 const res = await app.request('/api/v1/admin%2Fsecret')27062707 expect(res.status).toBe(200)2708 expect(await res.text()).toBe('/admin%2Fsecret')2709 })27102711 it('Should preserve encoded percent characters after stripping the prefix', async () => {2712 const app = new Hono()2713 app.mount('/api', anotherApp)27142715 const res = await app.request('/api/foo%252Fbar')27162717 expect(res.status).toBe(200)2718 expect(await res.text()).toBe('/foo%252Fbar')2719 })2720 })27212722 describe('With fetch', () => {2723 const anotherApp = async (req: Request, env: {}, executionContext: ExecutionContext) => {2724 const path = getPath(req)2725 if (path === '/') {
1034 unmodified lines