File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { patchProp } from '../src/patchProp'
2
2
import { render , h } from '../src'
3
+ import { mockWarn } from '@vue/shared'
3
4
4
5
describe ( 'runtime-dom: props patching' , ( ) => {
6
+ mockWarn ( )
7
+
5
8
test ( 'basic' , ( ) => {
6
9
const el = document . createElement ( 'div' )
7
10
patchProp ( el , 'id' , null , 'foo' )
@@ -92,4 +95,16 @@ describe('runtime-dom: props patching', () => {
92
95
patchProp ( el , 'srcObject' , null , null )
93
96
expect ( el . srcObject ) . toBe ( intiialValue )
94
97
} )
98
+
99
+ test ( 'catch and warn prop set TypeError' , ( ) => {
100
+ const el = document . createElement ( 'div' )
101
+ Object . defineProperty ( el , 'someProp' , {
102
+ set ( ) {
103
+ throw new TypeError ( 'Invalid type' )
104
+ }
105
+ } )
106
+ patchProp ( el , 'someProp' , null , 'foo' )
107
+
108
+ expect ( `Failed setting prop "someProp" on <div>` ) . toHaveBeenWarnedLast ( )
109
+ } )
95
110
} )
Original file line number Diff line number Diff line change 1
1
// __UNSAFE__
2
2
// Reason: potentially setting innerHTML.
3
3
// This can come from explicit usage of v-html or innerHTML as a prop in render
4
+
5
+ import { warn } from '@vue/runtime-core'
6
+
4
7
// functions. The user is reponsible for using them with only trusted content.
5
8
export function patchDOMProp (
6
9
el : any ,
@@ -35,6 +38,17 @@ export function patchDOMProp(
35
38
// e.g. <div :id="null">
36
39
el [ key ] = ''
37
40
} else {
38
- el [ key ] = value
41
+ // some properties perform value validation and throw
42
+ try {
43
+ el [ key ] = value
44
+ } catch ( e ) {
45
+ if ( __DEV__ ) {
46
+ warn (
47
+ `Failed setting prop "${ key } " on <${ el . tagName . toLowerCase ( ) } >: ` +
48
+ `value ${ value } is invalid.` ,
49
+ e
50
+ )
51
+ }
52
+ }
39
53
}
40
54
}
You can’t perform that action at this time.
0 commit comments