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

Commit

Permalink
fix($location): remove query args when passed in object
Browse files Browse the repository at this point in the history
Query args will be removed from $location search object if they are passed in as null or undefined object properties

Closes #6565
  • Loading branch information
SekibOmazic authored and IgorMinar committed Jul 1, 2014
1 parent 7088ed1 commit a26acb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
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

0 comments on commit a26acb6

Please sign in to comment.