Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 3 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
createSerialPromiseQueue,
emptyCssComments,
encodeURIPath,
escapeReplaceValue,
generateCodeFrame,
getHash,
getPackageManagerCommand,
Expand Down Expand Up @@ -2754,12 +2755,12 @@ async function compileLightningCSS(
switch (dep.type) {
case 'url':
if (skipUrlReplacer(dep.url)) {
css = css.replace(dep.placeholder, dep.url)
css = css.replace(dep.placeholder, escapeReplaceValue(dep.url))
break
}
deps.add(dep.url)
if (urlReplacer) {
css = css.replace(dep.placeholder, await urlReplacer(dep.url, id))
css = css.replace(dep.placeholder, escapeReplaceValue(await urlReplacer(dep.url, id)))
}
break
default:
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,10 @@ export function escapeRegex(str: string): string {
return str.replace(escapeRegexRE, '\\$&')
}

export function escapeReplaceValue(str: string): string {
return str.replaceAll('$', '$$$$' /* this is escaped $$ */)
}

type CommandType = 'install' | 'uninstall' | 'update'
export function getPackageManagerCommand(
type: CommandType = 'install',
Expand Down