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

Commit a26acb6

Browse files
SekibOmazicIgorMinar
authored andcommitted
fix($location): remove query args when passed in object
Query args will be removed from $location search object if they are passed in as null or undefined object properties Closes #6565
1 parent 7088ed1 commit a26acb6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ng/location.js

+5
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ LocationHashbangInHtml5Url.prototype =
446446
if (isString(search)) {
447447
this.$$search = parseKeyValue(search);
448448
} else if (isObject(search)) {
449+
// remove object undefined or null properties
450+
forEach(search, function(value, key) {
451+
if (value == null) delete search[key];
452+
});
453+
449454
this.$$search = search;
450455
} else {
451456
throw $locationMinErr('isrcharg',

test/ng/locationSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ describe('$location', function() {
117117
});
118118

119119

120+
it('search() should remove multiple parameters', function() {
121+
url.search({one: 1, two: true});
122+
expect(url.search()).toEqual({one: 1, two: true});
123+
url.search({one: null, two: null});
124+
expect(url.search()).toEqual({});
125+
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b#hash');
126+
});
127+
128+
120129
it('search() should handle multiple value', function() {
121130
url.search('a&b');
122131
expect(url.search()).toEqual({a: true, b: true});

0 commit comments

Comments
 (0)