Skip to content

Commit 199d888

Browse files
fix($location): decode non-component special chars in Hashbang URLS
Fixes angular#16316 (comment)
1 parent 8b69d91 commit 199d888

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ var locationPrototype = {
422422
}
423423

424424
var match = PATH_MATCH.exec(url);
425-
if (match[1] || url === '') this.path(decodeURI(match[1]));
425+
if (match[1] || url === '') this.path((this.$$html5 ? decodeURI : decodeURIComponent)(match[1]));
426426
if (match[2] || match[1] || url === '') this.search(match[3] || '');
427427
this.hash(match[5] || '');
428428

test/ng/locationSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ describe('$location', function() {
673673
locationUrl.search({'q': '4/5 6'});
674674
expect(locationUrl.absUrl()).toEqual('http://host.com?q=4%2F5%206');
675675
});
676+
677+
it('url() should decode non-component special characters in hashbang mode', function() {
678+
var locationUrl = new LocationHashbangUrl('http://host.com', 'http://host.com');
679+
locationUrl.$$parse('http://host.com');
680+
locationUrl.url('/foo%3Abar');
681+
expect(locationUrl.path()).toEqual('/foo:bar');
682+
});
683+
684+
it('url() should not decode non-component special characters in html5 mode', function() {
685+
var locationUrl = new LocationHtml5Url('http://host.com', 'http://host.com');
686+
locationUrl.$$parse('http://host.com');
687+
locationUrl.url('/foo%3Abar');
688+
expect(locationUrl.path()).toEqual('/foo%3Abar');
689+
});
676690
});
677691
});
678692

0 commit comments

Comments
 (0)