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

fix($location): allow empty string URLs to reset path, search, and hash #10064

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ var locationPrototype = {
return this.$$url;

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

return this;
Expand Down
8 changes: 8 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ describe('$location', function() {
expect(url.hash()).toBe('');
});

it('url() should change path when empty string specified', function() {
url.url('');

expect(url.path()).toBe('/');
expect(url.search()).toEqual({});
expect(url.hash()).toBe('');
});


it('replace should set $$replace flag and return itself', function() {
expect(url.$$replace).toBe(false);
Expand Down