diff --git a/src/ng/location.js b/src/ng/location.js index 9bb4d417cfe2..3647f7bf51c8 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -417,6 +417,14 @@ LocationHashbangInHtml5Url.prototype = if (isString(search)) { this.$$search = parseKeyValue(search); } else if (isObject(search)) { + // remove object undefined or null properties + for (var property in search) { + if (search.hasOwnProperty(property)) { + if (isUndefined(search[property]) || search[property] === null) { + delete search[property]; + } + } + } this.$$search = search; } else { throw $locationMinErr('isrcharg', diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index ff823d306efd..48d40f6bb4f8 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -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});