export function getEscapedPropName(key: string): string {
return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key
}
-
-export const cssVarNameEscapeSymbolsRE: RegExp =
- /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g
-
-export function getEscapedCssVarName(
- key: string,
- doubleEscape: boolean,
-): string {
- return key.replace(cssVarNameEscapeSymbolsRE, s =>
- doubleEscape ? `\\\\${s}` : `\\${s}`,
- )
-}
processExpression,
} from '@vue/compiler-dom'
import type { SFCDescriptor } from '../parse'
-import { getEscapedCssVarName } from '../script/utils'
import type { PluginCreator } from 'postcss'
import hash from 'hash-sum'
+import { getEscapedCssVarName } from '@vue/shared'
export const CSS_VARS_HELPER = `useCssVars`
app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})
+
+ test('escape css var name', () => {
+ const container = document.createElement('div')
+ container.innerHTML = `<div style="padding: 4px;--foo\\.bar:red;"></div>`
+ const app = createSSRApp({
+ setup() {
+ useCssVars(() => ({
+ 'foo.bar': 'red',
+ }))
+ return () => h(Child)
+ },
+ })
+ const Child = {
+ setup() {
+ return () => h('div', { style: 'padding: 4px' })
+ },
+ }
+ app.mount(container)
+ expect(`Hydration style mismatch`).not.toHaveBeenWarned()
+ })
})
describe('data-allow-mismatch', () => {
PatchFlags,
ShapeFlags,
def,
+ getEscapedCssVarName,
includeBooleanAttr,
isBooleanAttr,
isKnownHtmlAttr,
) {
const cssVars = instance.getCssVars()
for (const key in cssVars) {
- expectedMap.set(`--${key}`, String(cssVars[key]))
+ expectedMap.set(
+ `--${getEscapedCssVarName(key, false)}`,
+ String(cssVars[key]),
+ )
}
}
if (vnode === root && instance.parent) {
export function escapeHtmlComment(src: string): string {
return src.replace(commentStripRE, '')
}
+
+export const cssVarNameEscapeSymbolsRE: RegExp =
+ /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g
+
+export function getEscapedCssVarName(
+ key: string,
+ doubleEscape: boolean,
+): string {
+ return key.replace(cssVarNameEscapeSymbolsRE, s =>
+ doubleEscape ? `\\\\${s}` : `\\${s}`,
+ )
+}