@@ -11122,23 +11122,42 @@ describe('$compile', function() {
11122
11122
} ) ;
11123
11123
11124
11124
it ( 'should use $$sanitizeUri when working with svg and xlink:href' , function ( ) {
11125
+ var $$sanitizeUri = jasmine . createSpy ( '$$sanitizeUri' ) ;
11126
+ module ( function ( $provide ) {
11127
+ $provide . value ( '$$sanitizeUri' , $$sanitizeUri ) ;
11128
+ } ) ;
11129
+ inject ( function ( $compile , $rootScope ) {
11130
+ element = $compile ( '<svg><a xlink:href="{{ testUrl }}"></a></svg>' ) ( $rootScope ) ;
11131
+
11132
+ //both of these fail the RESOURCE_URL test, that shouldn't be run
11133
+ $rootScope . testUrl = 'https://bad.example.org' ;
11134
+ $$sanitizeUri . and . returnValue ( 'https://clean.example.org' ) ;
11135
+
11136
+ $rootScope . $apply ( ) ;
11137
+ expect ( element . find ( 'a' ) . attr ( 'xlink:href' ) ) . toBe ( 'https://clean.example.org' ) ;
11138
+ expect ( $$sanitizeUri ) . toHaveBeenCalledWith ( $rootScope . testUrl , false ) ;
11139
+ } ) ;
11140
+ } ) ;
11141
+
11142
+ it ( 'should use $$sanitizeUri when working with svg and xlink:href through ng-href' , function ( ) {
11125
11143
var $$sanitizeUri = jasmine . createSpy ( '$$sanitizeUri' ) ;
11126
11144
module ( function ( $provide ) {
11127
11145
$provide . value ( '$$sanitizeUri' , $$sanitizeUri ) ;
11128
11146
} ) ;
11129
11147
inject ( function ( $compile , $rootScope ) {
11130
11148
element = $compile ( '<svg><a xlink:href="" ng-href="{{ testUrl }}"></a></svg>' ) ( $rootScope ) ;
11131
- $rootScope . testUrl = 'evilUrl' ;
11149
+ //both of these fail the RESOURCE_URL test, that shouldn't be run
11150
+ $rootScope . testUrl = 'https://bad.example.org' ;
11151
+ $$sanitizeUri . and . returnValue ( 'https://clean.example.org' ) ;
11132
11152
11133
- $$sanitizeUri . and . returnValue ( 'someSanitizedUrl' ) ;
11134
11153
$rootScope . $apply ( ) ;
11135
- expect ( element . find ( 'a' ) . prop ( 'href' ) . baseVal ) . toBe ( 'someSanitizedUrl ' ) ;
11154
+ expect ( element . find ( 'a' ) . prop ( 'href' ) . baseVal ) . toBe ( 'https://clean.example.org ' ) ;
11136
11155
expect ( $$sanitizeUri ) . toHaveBeenCalledWith ( $rootScope . testUrl , false ) ;
11137
11156
} ) ;
11138
11157
} ) ;
11139
11158
11140
11159
11141
- it ( 'should use $$sanitizeUri when working with svg and xlink:href' , function ( ) {
11160
+ it ( 'should use $$sanitizeUri when working with svg and xlink:href through ng-href ' , function ( ) {
11142
11161
var $$sanitizeUri = jasmine . createSpy ( '$$sanitizeUri' ) ;
11143
11162
module ( function ( $provide ) {
11144
11163
$provide . value ( '$$sanitizeUri' , $$sanitizeUri ) ;
@@ -11153,6 +11172,18 @@ describe('$compile', function() {
11153
11172
expect ( $$sanitizeUri ) . toHaveBeenCalledWith ( $rootScope . testUrl , false ) ;
11154
11173
} ) ;
11155
11174
} ) ;
11175
+
11176
+
11177
+ it ( 'should have a RESOURCE_URL context for xlink:href by default' , function ( ) {
11178
+ inject ( function ( $compile , $rootScope ) {
11179
+ element = $compile ( '<svg><whatever xlink:href="{{ testUrl }}"></whatever></svg>' ) ( $rootScope ) ;
11180
+ $rootScope . testUrl = 'https://bad.example.org' ;
11181
+
11182
+ expect ( function ( ) {
11183
+ $rootScope . $apply ( ) ;
11184
+ } ) . toThrowError ( / \$ s c e : i n s e c u r l / ) ;
11185
+ } ) ;
11186
+ } ) ;
11156
11187
} ) ;
11157
11188
11158
11189
describe ( 'interpolation on HTML DOM event handler attributes onclick, onXYZ, formaction' , function ( ) {
0 commit comments