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

Commit f3f3c88

Browse files
committed
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 eaa1d00 commit f3f3c88

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/ng/location.js

+6
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ LocationHashbangInHtml5Url.prototype =
417417
if (isString(search)) {
418418
this.$$search = parseKeyValue(search);
419419
} else if (isObject(search)) {
420+
// remove object undefined or null properties
421+
Object.keys(search).forEach(function(key) {
422+
if (isUndefined(search[key]) || search[key] === null) {
423+
delete search[key];
424+
}
425+
});
420426
this.$$search = search;
421427
} else {
422428
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)