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(html): transform relative path with long base in /index.html #10990

Merged
merged 6 commits into from Nov 22, 2022

Conversation

candy-Tong
Copy link
Contributor

@candy-Tong candy-Tong commented Nov 19, 2022

Description

fix: #10989

I found that the url replacer function is not correctly replace the url.

  const replacer = (url: string) =>
    path.posix.join(
      devBase,
      path.posix.relative(originalUrl, devBase),
      url.slice(1)
    )

when the devBase is /a/b/c
originalUrl /a/b/c/d/e
path.posix.relative(originalUrl, devBase) will be '../..'
so ./src/mian.ts will be change to /a/src/main.ts

Additional context


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.

@bluwy bluwy added feat: html p3-minor-bug An edge case that only affects very specific usage (priority) labels Nov 19, 2022
@bluwy bluwy changed the title fix: transform relative path uncorrectly in /index.html #10989 fix(html): transform relative path with long base in /index.html Nov 19, 2022
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@benmccann
Copy link
Collaborator

It would be nice to add a unit test for processSrcSetSync to ensure we haven't broken anything and prevent regressions

@candy-Tong
Copy link
Contributor Author

It would be nice to add a unit test for processSrcSetSync to ensure we haven't broken anything and prevent regressions

I also found that there is already a test case here to test the srcset. May be we needn't to add a single unit test abount processSrcSetSync?

image

@benmccann
Copy link
Collaborator

It seems like there's a case that's not currently tested if there's a bug that this is fixing so it'd be nice to address that. I thought a unit test might be a lightweight way to do it, but whether it's a unit test or integration test probably doesn't matter so much.

@candy-Tong candy-Tong requested review from benmccann and removed request for bluwy November 21, 2022 12:48
benmccann
benmccann previously approved these changes Nov 22, 2022
packages/vite/src/node/__tests__/utils.spec.ts Outdated Show resolved Hide resolved
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@patak-dev patak-dev merged commit 752740c into vitejs:main Nov 22, 2022
fc pushed a commit to fc/vite that referenced this pull request Nov 23, 2022
…ejs#10990)

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
fix vitejs#10989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: html p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transform relative path uncorrectly in /index.html when using long base url
4 participants