mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-21 10:05:34 +08:00
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
This commit is contained in:
@@ -446,6 +446,11 @@ LocationHashbangInHtml5Url.prototype =
|
||||
if (isString(search)) {
|
||||
this.$$search = parseKeyValue(search);
|
||||
} else if (isObject(search)) {
|
||||
// remove object undefined or null properties
|
||||
forEach(search, function(value, key) {
|
||||
if (value == null) delete search[key];
|
||||
});
|
||||
|
||||
this.$$search = search;
|
||||
} else {
|
||||
throw $locationMinErr('isrcharg',
|
||||
|
||||
@@ -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});
|
||||
|
||||
Reference in New Issue
Block a user