diff --git a/src/ng/location.js b/src/ng/location.js index c315551006ac..2d5f805119b8 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -37,10 +37,10 @@ function parseAppUrl(relativeUrl, locationObj, appBase) { relativeUrl = '/' + relativeUrl; } var match = urlResolve(relativeUrl, appBase); - locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ? + locationObj.$$path = tryDecodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ? match.pathname.substring(1) : match.pathname); locationObj.$$search = parseKeyValue(match.search); - locationObj.$$hash = decodeURIComponent(match.hash); + locationObj.$$hash = tryDecodeURIComponent(match.hash); // make sure path starts with '/'; if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') { diff --git a/src/ng/urlUtils.js b/src/ng/urlUtils.js index dfd3c5db989c..2b5b0577326f 100644 --- a/src/ng/urlUtils.js +++ b/src/ng/urlUtils.js @@ -68,8 +68,12 @@ function urlResolve(url, base) { if (msie) { // Normalize before parse. Refer Implementation Notes on why this is // done in two steps on IE. - urlParsingNode.setAttribute("href", href); - href = urlParsingNode.href; + try { + urlParsingNode.setAttribute("href", href); + href = urlParsingNode.href; + } catch (e) { + href = ''; + } } urlParsingNode.setAttribute('href', href); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 5a338729cf00..2008a7d7e966 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -459,6 +459,16 @@ describe('$location', function() { expect(url.hash()).toBe('x <>#'); }); + + it('should not break on invalid URLs', function() { + url = new LocationHtml5Url('http://example.com/'); + url.$$parse('http://example.com/%?filter=%%U65-*55z65>ß.2á.3á02312-3-214.32@#%7B%7D%5D%5B%%%'); + expect(url.path()).toBe('/'); + expect(url.search()).toEqual({'filter': undefined}); + expect(url.hash()).toBeUndefined(); + }); + + it('should decode pluses as spaces in urls', function() { url = new LocationHtml5Url('http://host.com/'); url.$$parse('http://host.com/?a+b=c+d');