File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -88,4 +88,38 @@ describe('runtime-dom: attrs patching', () => {
8888 expect ( el2 . dataset . test ) . toBe ( undefined )
8989 expect ( testvalue ) . toBe ( obj )
9090 } )
91+
92+ // #13946
93+ test ( 'sandbox should be handled as attribute even if property exists' , ( ) => {
94+ const iframe = document . createElement ( 'iframe' ) as any
95+ let propSetCount = 0
96+ // simulate sandbox property in jsdom environment
97+ Object . defineProperty ( iframe , 'sandbox' , {
98+ configurable : true ,
99+ enumerable : true ,
100+ get ( ) {
101+ return this . _sandbox
102+ } ,
103+ set ( v ) {
104+ propSetCount ++
105+ this . _sandbox = v
106+ } ,
107+ } )
108+
109+ patchProp ( iframe , 'sandbox' , null , 'allow-scripts' )
110+ expect ( iframe . getAttribute ( 'sandbox' ) ) . toBe ( 'allow-scripts' )
111+ expect ( propSetCount ) . toBe ( 0 )
112+
113+ patchProp ( iframe , 'sandbox' , 'allow-scripts' , null )
114+ expect ( iframe . hasAttribute ( 'sandbox' ) ) . toBe ( false )
115+ expect ( iframe . getAttribute ( 'sandbox' ) ) . toBe ( null )
116+ expect ( propSetCount ) . toBe ( 0 )
117+
118+ patchProp ( iframe , 'sandbox' , null , '' )
119+ expect ( iframe . getAttribute ( 'sandbox' ) ) . toBe ( '' )
120+ expect ( iframe . hasAttribute ( 'sandbox' ) ) . toBe ( true )
121+ expect ( propSetCount ) . toBe ( 0 )
122+
123+ delete iframe . sandbox
124+ } )
91125} )
Original file line number Diff line number Diff line change @@ -111,6 +111,13 @@ function shouldSetAsProp(
111111 return false
112112 }
113113
114+ // #13946 iframe.sandbox should always be set as attribute since setting
115+ // the property to null results in 'null' string, and setting to empty string
116+ // enables the most restrictive sandbox mode instead of no sandboxing.
117+ if ( key === 'sandbox' && el . tagName === 'IFRAME' ) {
118+ return false
119+ }
120+
114121 // #1787, #2840 form property on form elements is readonly and must be set as
115122 // attribute.
116123 if ( key === 'form' ) {
You can’t perform that action at this time.
0 commit comments