File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -440,7 +440,7 @@ function $SceDelegateProvider() {
440440 // If we get here, then we will either sanitize the value or throw an exception.
441441 if ( type === SCE_CONTEXTS . MEDIA_URL || type === SCE_CONTEXTS . URL ) {
442442 // we attempt to sanitize non-resource URLs
443- return $$sanitizeUri ( maybeTrusted , type === SCE_CONTEXTS . MEDIA_URL ) ;
443+ return $$sanitizeUri ( maybeTrusted . toString ( ) , type === SCE_CONTEXTS . MEDIA_URL ) ;
444444 } else if ( type === SCE_CONTEXTS . RESOURCE_URL ) {
445445 if ( isResourceUrlAllowedByPolicy ( maybeTrusted ) ) {
446446 return maybeTrusted ;
Original file line number Diff line number Diff line change @@ -79,6 +79,42 @@ describe('ngHref', function() {
7979 } ) ) ;
8080 }
8181
82+
83+ it ( 'should bind numbers' , inject ( function ( $rootScope , $compile ) {
84+ element = $compile ( '<a ng-href="{{1234}}"></a>' ) ( $rootScope ) ;
85+ $rootScope . $digest ( ) ;
86+ expect ( element . attr ( 'href' ) ) . toEqual ( '1234' ) ;
87+ } ) ) ;
88+
89+
90+ it ( 'should bind and sanitize the result of a (custom) toString() function' , inject ( function ( $rootScope , $compile ) {
91+ $rootScope . value = { } ;
92+ element = $compile ( '<a ng-href="{{value}}"></a>' ) ( $rootScope ) ;
93+ $rootScope . $digest ( ) ;
94+ expect ( element . attr ( 'href' ) ) . toEqual ( '[object Object]' ) ;
95+
96+ function SafeClass ( ) { }
97+
98+ SafeClass . prototype . toString = function ( ) {
99+ return 'custom value' ;
100+ } ;
101+
102+ $rootScope . value = new SafeClass ( ) ;
103+ $rootScope . $digest ( ) ;
104+ expect ( element . attr ( 'href' ) ) . toEqual ( 'custom value' ) ;
105+
106+ function UnsafeClass ( ) { }
107+
108+ UnsafeClass . prototype . toString = function ( ) {
109+ return 'javascript:alert(1);' ;
110+ } ;
111+
112+ $rootScope . value = new UnsafeClass ( ) ;
113+ $rootScope . $digest ( ) ;
114+ expect ( element . attr ( 'href' ) ) . toEqual ( 'unsafe:javascript:alert(1);' ) ;
115+ } ) ) ;
116+
117+
82118 if ( isDefined ( window . SVGElement ) ) {
83119 describe ( 'SVGAElement' , function ( ) {
84120 it ( 'should interpolate the expression and bind to xlink:href' , inject ( function ( $compile , $rootScope ) {
You can’t perform that action at this time.
0 commit comments