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: encode path uri only #16212

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: i forgot one spot
  • Loading branch information
bluwy committed Mar 20, 2024
commit 9c444b3c5736d3d44666de809acc668967de82ad
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '../config'
import { checkPublicFile } from '../publicDir'
import {
encodeURIPath,
getHash,
injectQuery,
joinUrlSegments,
Expand Down Expand Up @@ -100,7 +101,7 @@ export function renderAssetUrlInJS(
)
const replacementString =
typeof replacement === 'string'
? JSON.stringify(encodeURI(replacement)).slice(1, -1)
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
: `"+${replacement.runtime}+"`
s.update(match.index, match.index + full.length, replacementString)
}
Expand All @@ -123,7 +124,7 @@ export function renderAssetUrlInJS(
)
const replacementString =
typeof replacement === 'string'
? JSON.stringify(encodeURI(replacement)).slice(1, -1)
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
: `"+${replacement.runtime}+"`
s.update(match.index, match.index + full.length, replacementString)
}
Expand Down Expand Up @@ -207,7 +208,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {

return {
code: `export default ${JSON.stringify(
url.startsWith('data:') ? url : encodeURI(url),
url.startsWith('data:') ? url : encodeURIPath(url),
)}`,
// Force rollup to keep this module from being shared between other entry points if it's an entrypoint.
// If the resulting chunk is empty, it will be removed in generateBundle.
Expand Down