mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-20 07:15:31 +08:00
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
This commit is contained in:
@@ -473,6 +473,7 @@ var locationPrototype = {
|
||||
search = search.toString();
|
||||
this.$$search = parseKeyValue(search);
|
||||
} else if (isObject(search)) {
|
||||
search = copy(search, {});
|
||||
// remove object undefined or null properties
|
||||
forEach(search, function(value, key) {
|
||||
if (value == null) delete search[key];
|
||||
|
||||
@@ -169,6 +169,16 @@ describe('$location', function() {
|
||||
});
|
||||
|
||||
|
||||
it('search() should copy object', function() {
|
||||
var obj = {one: 1, two: true, three: null};
|
||||
url.search(obj);
|
||||
expect(obj).toEqual({one: 1, two: true, three: null});
|
||||
obj.one = 'changed';
|
||||
expect(url.search()).toEqual({one: 1, two: true});
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?one=1&two#hash');
|
||||
});
|
||||
|
||||
|
||||
it('search() should change single parameter', function() {
|
||||
url.search({id: 'old', preserved: true});
|
||||
url.search('id', 'new');
|
||||
|
||||
Reference in New Issue
Block a user