@@ -4232,6 +4232,76 @@ describe('$compile', function() {
4232
4232
} ) ) ;
4233
4233
} ) ;
4234
4234
4235
+ describe ( 'form[action]' , function ( ) {
4236
+ it ( 'should pass through action attribute for the same domain' , inject ( function ( $compile , $rootScope , $sce ) {
4237
+ element = $compile ( '<form action="{{testUrl}}"></form>' ) ( $rootScope ) ;
4238
+ $rootScope . testUrl = "different_page" ;
4239
+ $rootScope . $apply ( ) ;
4240
+ expect ( element . attr ( 'action' ) ) . toEqual ( 'different_page' ) ;
4241
+ } ) ) ;
4242
+
4243
+ it ( 'should clear out action attribute for a different domain' , inject ( function ( $compile , $rootScope , $sce ) {
4244
+ element = $compile ( '<form action="{{testUrl}}"></form>' ) ( $rootScope ) ;
4245
+ $rootScope . testUrl = "http://a.different.domain.example.com" ;
4246
+ expect ( function ( ) { $rootScope . $apply ( ) } ) . toThrowMinErr (
4247
+ "$interpolate" , "interr" , "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " +
4248
+ "loading resource from url not allowed by $sceDelegate policy. URL: " +
4249
+ "http://a.different.domain.example.com" ) ;
4250
+ } ) ) ;
4251
+
4252
+ it ( 'should clear out JS action attribute' , inject ( function ( $compile , $rootScope , $sce ) {
4253
+ element = $compile ( '<form action="{{testUrl}}"></form>' ) ( $rootScope ) ;
4254
+ $rootScope . testUrl = "javascript:alert(1);" ;
4255
+ expect ( function ( ) { $rootScope . $apply ( ) } ) . toThrowMinErr (
4256
+ "$interpolate" , "interr" , "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " +
4257
+ "loading resource from url not allowed by $sceDelegate policy. URL: " +
4258
+ "javascript:alert(1);" ) ;
4259
+ } ) ) ;
4260
+
4261
+ it ( 'should clear out non-resource_url action attribute' , inject ( function ( $compile , $rootScope , $sce ) {
4262
+ element = $compile ( '<form action="{{testUrl}}"></form>' ) ( $rootScope ) ;
4263
+ $rootScope . testUrl = $sce . trustAsUrl ( "javascript:doTrustedStuff()" ) ;
4264
+ expect ( $rootScope . $apply ) . toThrowMinErr (
4265
+ "$interpolate" , "interr" , "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " +
4266
+ "loading resource from url not allowed by $sceDelegate policy. URL: javascript:doTrustedStuff()" ) ;
4267
+ } ) ) ;
4268
+
4269
+ it ( 'should pass through $sce.trustAs() values in action attribute' , inject ( function ( $compile , $rootScope , $sce ) {
4270
+ element = $compile ( '<form action="{{testUrl}}"></form>' ) ( $rootScope ) ;
4271
+ $rootScope . testUrl = $sce . trustAsResourceUrl ( "javascript:doTrustedStuff()" ) ;
4272
+ $rootScope . $apply ( ) ;
4273
+
4274
+ expect ( element . attr ( 'action' ) ) . toEqual ( 'javascript:doTrustedStuff()' ) ;
4275
+ } ) ) ;
4276
+ } ) ;
4277
+
4278
+ if ( ! msie || msie >= 11 ) {
4279
+ describe ( 'iframe[srcdoc]' , function ( ) {
4280
+ it ( 'should NOT set iframe contents for untrusted values' , inject ( function ( $compile , $rootScope , $sce ) {
4281
+ element = $compile ( '<iframe srcdoc="{{html}}"></iframe>' ) ( $rootScope ) ;
4282
+ $rootScope . html = '<div onclick="">hello</div>' ;
4283
+ expect ( function ( ) { $rootScope . $digest ( ) ; } ) . toThrowMinErr ( '$interpolate' , 'interr' , new RegExp (
4284
+ / C a n ' t i n t e r p o l a t e : { { h t m l } } \n / . source +
4285
+ / [ ^ [ ] * \[ \$ s c e : u n s a f e \] A t t e m p t i n g t o u s e a n u n s a f e v a l u e i n a s a f e c o n t e x t ./ . source ) ) ;
4286
+ } ) ) ;
4287
+
4288
+ it ( 'should NOT set html for wrongly typed values' , inject ( function ( $rootScope , $compile , $sce ) {
4289
+ element = $compile ( '<iframe srcdoc="{{html}}"></iframe>' ) ( $rootScope ) ;
4290
+ $rootScope . html = $sce . trustAsCss ( '<div onclick="">hello</div>' ) ;
4291
+ expect ( function ( ) { $rootScope . $digest ( ) ; } ) . toThrowMinErr ( '$interpolate' , 'interr' , new RegExp (
4292
+ / C a n ' t i n t e r p o l a t e : { { h t m l } } \n / . source +
4293
+ / [ ^ [ ] * \[ \$ s c e : u n s a f e \] A t t e m p t i n g t o u s e a n u n s a f e v a l u e i n a s a f e c o n t e x t ./ . source ) ) ;
4294
+ } ) ) ;
4295
+
4296
+ it ( 'should set html for trusted values' , inject ( function ( $rootScope , $compile , $sce ) {
4297
+ element = $compile ( '<iframe srcdoc="{{html}}"></iframe>' ) ( $rootScope ) ;
4298
+ $rootScope . html = $sce . trustAsHtml ( '<div onclick="">hello</div>' ) ;
4299
+ $rootScope . $digest ( ) ;
4300
+ expect ( angular . lowercase ( element [ 0 ] . srcdoc ) ) . toEqual ( '<div onclick="">hello</div>' ) ;
4301
+ } ) ) ;
4302
+ } ) ;
4303
+ }
4304
+
4235
4305
describe ( 'ngAttr* attribute binding' , function ( ) {
4236
4306
4237
4307
it ( 'should bind after digest but not before' , inject ( function ( $compile , $rootScope ) {
0 commit comments