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

chore: join URL segments more safely #10590

Merged
merged 2 commits into from Oct 27, 2022
Merged

Conversation

benmccann
Copy link
Collaborator

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 use path.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 use path.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?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

patak-dev
patak-dev previously approved these changes Oct 23, 2022
@patak-dev patak-dev merged commit 675bf07 into vitejs:main Oct 27, 2022
@benmccann benmccann deleted the joinUrlSegments branch October 27, 2022 16:29
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.

None yet

3 participants