From 04591674fa26ad94821638b7624748cfe00c88a1 Mon Sep 17 00:00:00 2001 From: bullgare Date: Mon, 6 Oct 2014 18:23:25 +0400 Subject: [PATCH] Fixes bug when $location.search() is not returning search part of current url. Inluding tests. --- src/ng/location.js | 1 + test/ng/locationSpec.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/ng/location.js b/src/ng/location.js index f7275319dcb9..8b5e955f5114 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -475,6 +475,7 @@ LocationHashbangInHtml5Url.prototype = 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]; diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index d6cf2cbeb090..92a1448274b9 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -169,6 +169,16 @@ describe('$location', function() { }); + it('search() should not use given object directly', 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');