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: prevent crash on malformed URI #1977

Merged
merged 1 commit into from
Feb 11, 2021

Conversation

threepointone
Copy link
Contributor

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 like decodeURI(...) 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 the decodeURI call. It also gives a specific message when it encounters %PUBLIC.URL%, pointing folks to the vite docs for how it handles index.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:
image

After, malformed URI:
image

in-browser:
image

After, %PUBLIC_URL%
image

After, %PUBLIC_URL% in-browser
image

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 like `decodeURI(...)` 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 the `decodeURI` call. It also gives a specific message when it encounters `%PUBLIC.URL%`, pointing folks to the vite docs for how it handles `index.html`
@yyx990803 yyx990803 merged commit f1b0bc9 into vitejs:main Feb 11, 2021
@threepointone threepointone deleted the prevent-malformed-uri-crash branch February 11, 2021 14:54
@hyf0 hyf0 mentioned this pull request Aug 17, 2021
9 tasks
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.

2 participants