Skip to content
Myr

fix(serve-static): treat empty string content as found (#5062)

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

authored by Yusuke Wada · committed by GitHub · parent 97c6fe1 · Browse files · 2 files+16 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+16 added−1 removed

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

2 files+16 added−1 removed

modified:src/middleware/serve-static/index.test.ts+15 added
67 unmodified lines
68 expect(await res.text()).toBe('404 Not Found')69 expect(getContent).toBeCalledTimes(1)70 })7172 it('Should return 200 response for empty string content - /static/empty.txt', async () => {73 const onNotFound = vi.fn()74 const app = new Hono().use(75 '*',76 baseServeStatic({77 getContent: async () => '',78 onNotFound,79 })80 )81 const res = await app.request('/static/empty.txt')82 expect(res.status).toBe(200)83 expect(await res.text()).toBe('')84 expect(onNotFound).not.toBeCalled()85 })8687 it('Should not allow a directory traversal - /static/%2e%2e/static/hello.html', async () => {88 const res = await app.fetch({89 method: 'GET',90 url: 'http://localhost/static/%2e%2e/static/hello.html',
231 unmodified lines
modified:src/middleware/serve-static/index.ts+1 added-1 removed