File tree 5 files changed +38
-14
lines changed
5 files changed +38
-14
lines changed Original file line number Diff line number Diff line change @@ -121,15 +121,3 @@ export const propNameEscapeSymbolsRE: RegExp =
121
121
export function getEscapedPropName ( key : string ) : string {
122
122
return propNameEscapeSymbolsRE . test ( key ) ? JSON . stringify ( key ) : key
123
123
}
124
-
125
- export const cssVarNameEscapeSymbolsRE : RegExp =
126
- / [ ! " # $ % & ' ( ) * + , . / : ; < = > ? @ [ \\ \] ^ ` { | } ~ ] / g
127
-
128
- export function getEscapedCssVarName (
129
- key : string ,
130
- doubleEscape : boolean ,
131
- ) : string {
132
- return key . replace ( cssVarNameEscapeSymbolsRE , s =>
133
- doubleEscape ? `\\\\${ s } ` : `\\${ s } ` ,
134
- )
135
- }
Original file line number Diff line number Diff line change 8
8
processExpression ,
9
9
} from '@vue/compiler-dom'
10
10
import type { SFCDescriptor } from '../parse'
11
- import { getEscapedCssVarName } from '../script/utils'
12
11
import type { PluginCreator } from 'postcss'
13
12
import hash from 'hash-sum'
13
+ import { getEscapedCssVarName } from '@vue/shared'
14
14
15
15
export const CSS_VARS_HELPER = `useCssVars`
16
16
Original file line number Diff line number Diff line change @@ -2021,6 +2021,26 @@ describe('SSR hydration', () => {
2021
2021
app . mount ( container )
2022
2022
expect ( `Hydration style mismatch` ) . not . toHaveBeenWarned ( )
2023
2023
} )
2024
+
2025
+ test ( 'escape css var name' , ( ) => {
2026
+ const container = document . createElement ( 'div' )
2027
+ container . innerHTML = `<div style="padding: 4px;--foo\\.bar:red;"></div>`
2028
+ const app = createSSRApp ( {
2029
+ setup ( ) {
2030
+ useCssVars ( ( ) => ( {
2031
+ 'foo.bar' : 'red' ,
2032
+ } ) )
2033
+ return ( ) => h ( Child )
2034
+ } ,
2035
+ } )
2036
+ const Child = {
2037
+ setup ( ) {
2038
+ return ( ) => h ( 'div' , { style : 'padding: 4px' } )
2039
+ } ,
2040
+ }
2041
+ app . mount ( container )
2042
+ expect ( `Hydration style mismatch` ) . not . toHaveBeenWarned ( )
2043
+ } )
2024
2044
} )
2025
2045
2026
2046
describe ( 'data-allow-mismatch' , ( ) => {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
PatchFlags ,
19
19
ShapeFlags ,
20
20
def ,
21
+ getEscapedCssVarName ,
21
22
includeBooleanAttr ,
22
23
isBooleanAttr ,
23
24
isKnownHtmlAttr ,
@@ -915,7 +916,10 @@ function resolveCssVars(
915
916
) {
916
917
const cssVars = instance . getCssVars ( )
917
918
for ( const key in cssVars ) {
918
- expectedMap . set ( `--${ key } ` , String ( cssVars [ key ] ) )
919
+ expectedMap . set (
920
+ `--${ getEscapedCssVarName ( key , false ) } ` ,
921
+ String ( cssVars [ key ] ) ,
922
+ )
919
923
}
920
924
}
921
925
if ( vnode === root && instance . parent ) {
Original file line number Diff line number Diff line change @@ -50,3 +50,15 @@ const commentStripRE = /^-?>|<!--|-->|--!>|<!-$/g
50
50
export function escapeHtmlComment ( src : string ) : string {
51
51
return src . replace ( commentStripRE , '' )
52
52
}
53
+
54
+ export const cssVarNameEscapeSymbolsRE : RegExp =
55
+ / [ ! " # $ % & ' ( ) * + , . / : ; < = > ? @ [ \\ \] ^ ` { | } ~ ] / g
56
+
57
+ export function getEscapedCssVarName (
58
+ key : string ,
59
+ doubleEscape : boolean ,
60
+ ) : string {
61
+ return key . replace ( cssVarNameEscapeSymbolsRE , s =>
62
+ doubleEscape ? `\\\\${ s } ` : `\\${ s } ` ,
63
+ )
64
+ }
You can’t perform that action at this time.
0 commit comments