diff --git a/src/ng/sanitizeUri.js b/src/ng/sanitizeUri.js
index b8b2d8bcdbd1..8d19c75e3bb2 100644
--- a/src/ng/sanitizeUri.js
+++ b/src/ng/sanitizeUri.js
@@ -69,9 +69,15 @@ function $$SanitizeUriProvider() {
this.$get = function() {
return function sanitizeUri(uri, isMediaUrl) {
+ if (!uri) return uri;
var regex = isMediaUrl ? imgSrcSanitizationWhitelist : aHrefSanitizationWhitelist;
var normalizedVal;
- normalizedVal = urlResolve(uri && uri.trim()).href;
+ try {
+ normalizedVal = urlResolve(uri.trim()).href;
+ } catch(e) {
+ console.log(uri);
+ throw e;
+ }
if (normalizedVal !== '' && !normalizedVal.match(regex)) {
return 'unsafe:' + normalizedVal;
}
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 73446d8ca6c8..92fd17f0904f 100644
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -11173,13 +11173,13 @@ describe('$compile', function() {
$rootScope.$digest();
expect(element.attr('src')).toEqual('unsafe:untrusted:foo();ponies');
- element = $compile('')($rootScope);
- $rootScope.testUrl = $sce.trustAsUrl('untrusted:foo();');
+ element = $compile('')($rootScope);
+ $rootScope.testUrl2 = $sce.trustAsUrl('xyz;');
$rootScope.$digest();
- expect(element.attr('src')).toEqual('http://untrusted:foo();');
+ expect(element.attr('src')).toEqual('http://xyz;');
- element = $compile('')($rootScope);
- $rootScope.testUrl = $sce.trustAsUrl('untrusted:foo();');
+ element = $compile('')($rootScope);
+ $rootScope.testUrl3 = $sce.trustAsUrl('untrusted:foo();');
$rootScope.$digest();
expect(element.attr('src')).toEqual('unsafe:untrusted:foo();untrusted:foo();');
}));
@@ -11220,7 +11220,7 @@ describe('$compile', function() {
expect(element.attr('src')).toEqual('someSanitizedUrl');
element = $compile('')($rootScope);
- $rootScope.testUrl = $sce.trustAsUrl('javascript:foo();');
+ $rootScope.testUrl = $sce.trustAsUrl('xyz');
$rootScope.$digest();
expect(element.attr('src')).toEqual('someSanitizedUrl');
});