elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.45k stars 223 forks source link

Static file with a file name containing spaces was not found #454

Closed zulfio closed 9 months ago

zulfio commented 9 months ago

What version of Elysia.JS is running?

0.7

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

  1. Create a static API route
  2. Attempt to access the route using the file name with spaces.

When attempting to access a static route with a file name containing spaces, the route/file is not found. However, if the file name does not contain spaces, the route works fine.

What is the expected behavior?

The expected behavior is that the static API route should be accessible and functional regardless of whether the file name contains spaces.

What do you see instead?

/public/static/2024/01/Screenshot.png - Error - 404 - NOT_FOUND when the file name contains spaces, the static API route is not found or accessible.

Additional information

package.json

"@elysiajs/cors": "^0.8.0",
"@elysiajs/static": "^0.8.1",
"elysia": "latest",

code:

app.use(
    staticPlugin({
      assets: "./src/uploads",
      prefix: "/public",
    })
  );

working fine: http://localhost:5000/public/static/2024/01/Screenshot1.png error: http://localhost:5000/public/static/2024/01/Screenshot%201.png

zulfio commented 9 months ago

Oops my bad, we can set enableDecodeURI to true.

app.use(
    staticPlugin({
      assets: "./src/uploads",
      prefix: "/public",
      enableDecodeURI: true,
    })
  );