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

Commit c7a9009

Browse files
bullgarecaitp
authored andcommitted
fix($location): use clone of passed search() object
Fixes bug when $location.search() is not returning search part of current url. Previously, the location's internal search object could be set by passing an object to the search() method. Subsequent changes to the passed search object would be exposed when requesting the search object, but those changes would not appear in the composed url. Now, the object is cloned, so the result of location.search() should match the contents of location.absUrl(), provided the object returned from location.search() is not changed. Closes #9445
1 parent e15d2fd commit c7a9009

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/ng/location.js

+1
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ var locationPrototype = {
473473
search = search.toString();
474474
this.$$search = parseKeyValue(search);
475475
} else if (isObject(search)) {
476+
search = copy(search, {});
476477
// remove object undefined or null properties
477478
forEach(search, function(value, key) {
478479
if (value == null) delete search[key];

test/ng/locationSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ describe('$location', function() {
169169
});
170170

171171

172+
it('search() should copy object', function() {
173+
var obj = {one: 1, two: true, three: null};
174+
url.search(obj);
175+
expect(obj).toEqual({one: 1, two: true, three: null});
176+
obj.one = 'changed';
177+
expect(url.search()).toEqual({one: 1, two: true});
178+
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?one=1&two#hash');
179+
});
180+
181+
172182
it('search() should change single parameter', function() {
173183
url.search({id: 'old', preserved: true});
174184
url.search('id', 'new');

0 commit comments

Comments
 (0)