fix: prevent crash on malformed URI #1977
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was migrating from a
create-react-app
project, and my application wouldn't start. Looking at the terminal, I noticed vite had crashed, and it wasn't obvious why. Diving in, it looks likedecodeURI(...)
throws an error on bad URLs (which makes sense), but we shouldn't crash the server when that happens.This PR adds a
try/catch
around thedecodeURI
call. It also gives a specific message when it encounters%PUBLIC.URL%
, pointing folks to the vite docs for how it handlesindex.html
This PR does not add a test yet. I couldn't figure out where to do so. Should I add a new folder under
packages/playground
?Screenshots galore. Before:
After, malformed URI:
in-browser:
After,
%PUBLIC_URL%
After,
%PUBLIC_URL%
in-browser