fix(cssVars): correctly escape double quotes in SSR (#11784)
close #11779
This commit is contained in:
parent
9817c80187
commit
7b5b6e0275
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
@ -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>
|
||||
`,
|
||||
{
|
||||
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -59,6 +59,6 @@ export function getEscapedCssVarName(
|
|||
doubleEscape: boolean,
|
||||
): string {
|
||||
return key.replace(cssVarNameEscapeSymbolsRE, s =>
|
||||
doubleEscape ? `\\\\${s}` : `\\${s}`,
|
||||
doubleEscape ? (s === '"' ? '\\\\\\"' : `\\\\${s}`) : `\\${s}`,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue