Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8e285d0

Browse files
fix($location): dont throw while parsing invalid URLs
Fixes #6836
1 parent 50e72fc commit 8e285d0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/ng/location.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ function parseAppUrl(relativeUrl, locationObj, appBase) {
3737
relativeUrl = '/' + relativeUrl;
3838
}
3939
var match = urlResolve(relativeUrl, appBase);
40-
locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ?
40+
locationObj.$$path = tryDecodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ?
4141
match.pathname.substring(1) : match.pathname);
4242
locationObj.$$search = parseKeyValue(match.search);
43-
locationObj.$$hash = decodeURIComponent(match.hash);
43+
locationObj.$$hash = tryDecodeURIComponent(match.hash);
4444

4545
// make sure path starts with '/';
4646
if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') {

test/ng/locationSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,16 @@ describe('$location', function() {
459459
expect(url.hash()).toBe('x <>#');
460460
});
461461

462+
463+
it('should not break on invalid URLs', function() {
464+
url = new LocationHtml5Url('http://example.com/');
465+
url.$$parse('http://example.com/%?filter=%%U65-*55z65>ß.2á.3á02312-3-214.32@#%7B%7D%5D%5B%%%');
466+
expect(url.path()).toBe('/');
467+
expect(url.search()).toEqual({'filter': undefined});
468+
expect(url.hash()).toBeUndefined();
469+
});
470+
471+
462472
it('should decode pluses as spaces in urls', function() {
463473
url = new LocationHtml5Url('http://host.com/');
464474
url.$$parse('http://host.com/?a+b=c+d');

0 commit comments

Comments
 (0)