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

fix($location): decode non-component special chars in Hashbang URLS #16350

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ var locationPrototype = {
}

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

Expand Down
14 changes: 14 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,20 @@ describe('$location', function() {
locationUrl.search({'q': '4/5 6'});
expect(locationUrl.absUrl()).toEqual('http://host.com?q=4%2F5%206');
});

it('url() should decode non-component special characters in hashbang mode', function() {
var locationUrl = new LocationHashbangUrl('http://host.com', 'http://host.com');
locationUrl.$$parse('http://host.com');
locationUrl.url('/foo%3Abar');
expect(locationUrl.path()).toEqual('/foo:bar');
});

it('url() should not decode non-component special characters in html5 mode', function() {
var locationUrl = new LocationHtml5Url('http://host.com', 'http://host.com');
locationUrl.$$parse('http://host.com');
locationUrl.url('/foo%3Abar');
expect(locationUrl.path()).toEqual('/foo%3Abar');
});
});
});

Expand Down