Skip to content

Commit feec345

Browse files
SekibOmazicCameron Knight
authored and
Cameron Knight
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 angular#6565
1 parent 5663368 commit feec345

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
@@ -118,6 +118,15 @@ describe('$location', function() {
118118
});
119119

120120

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

0 commit comments

Comments
 (0)