Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(serveStatic): add guard to prevent reading empty folders #3639

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

oussamasf
Copy link
Contributor

@oussamasf oussamasf commented Nov 6, 2024

#3628

This PR addresses an issue where attempting to open an empty directory with Deno.open returns a ReadableStream, causing unexpected behavior. Specifically, it leads to a status code 200 instead of the expected 404 for directories.

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Nov 7, 2024

I think this function is supposed to determine if the path is a directory...
If so, this may be a bug in serve-static as a whole.

https://github.com/honojs/hono/blob/main/src/adapter/deno/serve-static.ts#L25

Am I mistaken...?

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Nov 7, 2024

@oussamasf

Adding the following to the beginning of your pull request is useful because it will automatically close the issue when it is merged!
Closes: https://github.com/honojs/hono/issues/3628

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.68%. Comparing base (394a8f5) to head (7d4561d).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3639      +/-   ##
==========================================
+ Coverage   90.52%   91.68%   +1.15%     
==========================================
  Files         159      159              
  Lines       10179    10135      -44     
  Branches     2843     2862      +19     
==========================================
+ Hits         9215     9292      +77     
+ Misses        962      841     -121     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yusukebe
Copy link
Member

yusukebe commented Nov 7, 2024

Hi @oussamasf !

Thank you for the PR. Seems to be good. But, we need to write tests. Could you add a test for it? You can put it to runtime-tests/deno/middleware.test.tsx.

@oussamasf
Copy link
Contributor Author

@EdamAme-x I replaced stat with the existing function
@yusukebe I added the minimum pattern (..as instructed in the comments of the test file)

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Nov 8, 2024

@oussamasf

Looks good to me! Thank you for your contribution.

@yusukebe yusukebe merged commit 65f2a3b into honojs:main Nov 8, 2024
16 checks passed
@alexgleason
Copy link

Thank you for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants