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(static): safe decode path #1459

Merged
merged 4 commits into from
Jul 19, 2023
Merged

fix(static): safe decode path #1459

merged 4 commits into from
Jul 19, 2023

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

nuxt/nuxt#22071

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

In some cases (such as a malformed URL) we might encounter an error when checking whether the URL is a static asset. However, we can be assured it is not a static asset and either throw a 404 if it has the static prefix, or simply early return from the handler and directly progress to the next handler, which can allow the user to correct the URL or throw their own error.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #1459 (c65d136) into main (3687d31) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1459   +/-   ##
=======================================
  Coverage   76.14%   76.14%           
=======================================
  Files          73       73           
  Lines        7428     7428           
  Branches      728      728           
=======================================
  Hits         5656     5656           
  Misses       1771     1771           
  Partials        1        1           

@pi0
Copy link
Member

pi0 commented Jul 19, 2023

I think we can use ufo.decodePath instead which has built-in try/catch safety (https://github.com/unjs/ufo/blob/main/src/encoding.ts#L124)

src/runtime/static.ts Outdated Show resolved Hide resolved
@danielroe danielroe changed the title fix: do not throw errors decoding static assets fix: do not throw error when decoding url Jul 19, 2023
@pi0 pi0 changed the title fix: do not throw error when decoding url fix(static): safe decode path Jul 19, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks!

@pi0 pi0 merged commit 88831dc into main Jul 19, 2023
@pi0 pi0 deleted the fix/catch-static-errors branch July 19, 2023 09:56
@pi0 pi0 mentioned this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants