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(cssVars): correctly escape double quotes in SSR #11784

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,13 @@ export default {
const count = ref(0)
const style = { color: 'red' }
const height = ref(0)
return (_ctx, _push, _parent, _attrs) => {
const _cssVars = { style: {
"--xxxxxxxx-count": (count.value),
"--xxxxxxxx-style\\\\.color": (style.color)
"--xxxxxxxx-style\\\\.color": (style.color),
"--xxxxxxxx-height\\\\ \\\\+\\\\ \\\\\\"px\\\\\\"": (height.value + "px")
}}
_push(\`<!--[--><div\${
_ssrRenderAttrs(_cssVars)
Expand Down
5 changes: 5 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ describe('SFC compile <script setup>', () => {
import { ref } from 'vue'
const count = ref(0)
const style = { color: 'red' }
const height = ref(0)
</script>
<template>
<div>{{ count }}</div>
Expand All @@ -614,6 +615,7 @@ describe('SFC compile <script setup>', () => {
<style>
div { color: v-bind(count) }
span { color: v-bind(style.color) }
span { color: v-bind(height + "px") }
</style>
`,
{
Expand All @@ -629,6 +631,9 @@ describe('SFC compile <script setup>', () => {
expect(content).not.toMatch(`useCssVars`)
expect(content).toMatch(`"--${mockId}-count": (count.value)`)
expect(content).toMatch(`"--${mockId}-style\\\\.color": (style.color)`)
expect(content).toMatch(
`"--${mockId}-height\\\\ \\\\+\\\\ \\\\\\"px\\\\\\"": (height.value + "px")`,
)
assertCode(content)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/escapeHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ export function getEscapedCssVarName(
doubleEscape: boolean,
): string {
return key.replace(cssVarNameEscapeSymbolsRE, s =>
doubleEscape ? `\\\\${s}` : `\\${s}`,
doubleEscape ? (s === '"' ? '\\\\\\"' : `\\\\${s}`) : `\\${s}`,
)
}