chore: join URL segments more safely #10590
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.
Description
We are appending the URL path to base path in numerous locations assuming that the base path ends with
/
. I would like to stop enforcing that the base path ends with/
(see #9236). This change implements much of what would be necessary, but is something that could be reviewed immediately and wouldn't have to wait for 4.0.I introduced a new helper called
joinUrlSegments
. In most of the cases, this helper wouldn't be necessary and we could just usepath.posix.join
. However, there's a couple cases where this helper might be preferred. E.g. if the URL includes the scheme then you cannot usepath.posix.join
because//
would be collapsed to/
. Also, if the base URL is./
it would be replaced with an empty string which may not be safe.Additional context
I did not expose
joinUrlSegments
, but we may wish to do that and encourage frameworks to use that method. This could be done in Vite 3.2. Frameworks that use this method will find it easier to migrate to Vite 4 assuming we make a breaking change and stop enforcing that URLs end with/
.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).