File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,16 @@ describe('ssr: renderAttrs', () => {
53
53
) . toBe ( ` foo="false"` ) // non boolean should render `false` as is
54
54
} )
55
55
56
+ test ( 'ingore non-renderable values' , ( ) => {
57
+ expect (
58
+ renderAttrs ( {
59
+ foo : { } ,
60
+ bar : [ ] ,
61
+ baz : ( ) => { }
62
+ } )
63
+ ) . toBe ( `` )
64
+ } )
65
+
56
66
test ( 'props to attrs' , ( ) => {
57
67
expect (
58
68
renderAttrs ( {
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ export function renderDynamicAttr(
45
45
value : unknown ,
46
46
tag ?: string
47
47
) : string {
48
- if ( value == null ) {
48
+ if ( ! isRenderableValue ( value ) ) {
49
49
return ``
50
50
}
51
51
const attrKey =
@@ -64,12 +64,20 @@ export function renderDynamicAttr(
64
64
// Render a v-bind attr with static key. The key is pre-processed at compile
65
65
// time and we only need to check and escape value.
66
66
export function renderAttr ( key : string , value : unknown ) : string {
67
- if ( value == null ) {
67
+ if ( ! isRenderableValue ( value ) ) {
68
68
return ``
69
69
}
70
70
return ` ${ key } ="${ escapeHtml ( value ) } "`
71
71
}
72
72
73
+ function isRenderableValue ( value : unknown ) : boolean {
74
+ if ( value == null ) {
75
+ return false
76
+ }
77
+ const type = typeof value
78
+ return type === 'string' || type === 'number' || type === 'boolean'
79
+ }
80
+
73
81
export function renderClass ( raw : unknown ) : string {
74
82
return escapeHtml ( normalizeClass ( raw ) )
75
83
}
You can’t perform that action at this time.
0 commit comments