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

fix($location): remove query args when passed in object #6573

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
8 changes: 8 additions & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ LocationHashbangInHtml5Url.prototype =
if (isString(search)) {
this.$$search = parseKeyValue(search);
} else if (isObject(search)) {
// remove object undefined or null properties
for (var property in search) {
if (search.hasOwnProperty(property)) {
if (isUndefined(search[property]) || search[property] === null) {
delete search[property];
}
}
}
this.$$search = search;
} else {
throw $locationMinErr('isrcharg',
Expand Down
9 changes: 9 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ describe('$location', function() {
});


it('search() should remove multiple parameters', function() {
url.search({one: 1, two: true});
expect(url.search()).toEqual({one: 1, two: true});
url.search({one: null, two: null});
expect(url.search()).toEqual({});
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b#hash');
});


it('search() should handle multiple value', function() {
url.search('a&b');
expect(url.search()).toEqual({a: true, b: true});
Expand Down