Skip to content

Commit 7b5b6e0

Browse files
authoredSep 3, 2024··
fix(cssVars): correctly escape double quotes in SSR (#11784)
close #11779
1 parent 9817c80 commit 7b5b6e0

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
 

‎packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,13 @@ export default {
880880
881881
const count = ref(0)
882882
const style = { color: 'red' }
883+
const height = ref(0)
883884
884885
return (_ctx, _push, _parent, _attrs) => {
885886
const _cssVars = { style: {
886887
"--xxxxxxxx-count": (count.value),
887-
"--xxxxxxxx-style\\\\.color": (style.color)
888+
"--xxxxxxxx-style\\\\.color": (style.color),
889+
"--xxxxxxxx-height\\\\ \\\\+\\\\ \\\\\\"px\\\\\\"": (height.value + "px")
888890
}}
889891
_push(\`<!--[--><div\${
890892
_ssrRenderAttrs(_cssVars)

‎packages/compiler-sfc/__tests__/compileScript.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ describe('SFC compile <script setup>', () => {
606606
import { ref } from 'vue'
607607
const count = ref(0)
608608
const style = { color: 'red' }
609+
const height = ref(0)
609610
</script>
610611
<template>
611612
<div>{{ count }}</div>
@@ -614,6 +615,7 @@ describe('SFC compile <script setup>', () => {
614615
<style>
615616
div { color: v-bind(count) }
616617
span { color: v-bind(style.color) }
618+
span { color: v-bind(height + "px") }
617619
</style>
618620
`,
619621
{
@@ -629,6 +631,9 @@ describe('SFC compile <script setup>', () => {
629631
expect(content).not.toMatch(`useCssVars`)
630632
expect(content).toMatch(`"--${mockId}-count": (count.value)`)
631633
expect(content).toMatch(`"--${mockId}-style\\\\.color": (style.color)`)
634+
expect(content).toMatch(
635+
`"--${mockId}-height\\\\ \\\\+\\\\ \\\\\\"px\\\\\\"": (height.value + "px")`,
636+
)
632637
assertCode(content)
633638
})
634639

‎packages/shared/src/escapeHtml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ export function getEscapedCssVarName(
5959
doubleEscape: boolean,
6060
): string {
6161
return key.replace(cssVarNameEscapeSymbolsRE, s =>
62-
doubleEscape ? `\\\\${s}` : `\\${s}`,
62+
doubleEscape ? (s === '"' ? '\\\\\\"' : `\\\\${s}`) : `\\${s}`,
6363
)
6464
}

0 commit comments

Comments
 (0)
Please sign in to comment.