mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-23 13:25:48 +00:00
fix(location): fix parameter handling on search()
This commit is contained in:
parent
61906d3517
commit
705c9d95bc
3 changed files with 51 additions and 11 deletions
4
docs/content/error/location/wpt.ngdoc
Normal file
4
docs/content/error/location/wpt.ngdoc
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
@ngdoc error
|
||||||
|
@name $location:wpt
|
||||||
|
@fullName Wrong parameter type
|
||||||
|
@description
|
||||||
|
|
@ -353,17 +353,24 @@ LocationHashbangInHtml5Url.prototype =
|
||||||
* @return {string} search
|
* @return {string} search
|
||||||
*/
|
*/
|
||||||
search: function(search, paramValue) {
|
search: function(search, paramValue) {
|
||||||
if (isUndefined(search))
|
switch (arguments.length) {
|
||||||
return this.$$search;
|
case 0:
|
||||||
|
return this.$$search;
|
||||||
if (isDefined(paramValue)) {
|
case 1:
|
||||||
if (paramValue === null) {
|
if (isString(search)) {
|
||||||
delete this.$$search[search];
|
this.$$search = parseKeyValue(search);
|
||||||
} else {
|
} else if (isObject(search)) {
|
||||||
this.$$search[search] = paramValue;
|
this.$$search = search;
|
||||||
}
|
} else {
|
||||||
} else {
|
throw $locationMinErr('wpt', 'First parameter of function must be string or an object.');
|
||||||
this.$$search = isString(search) ? parseKeyValue(search) : search;
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (paramValue == undefined || paramValue == null) {
|
||||||
|
delete this.$$search[search];
|
||||||
|
} else {
|
||||||
|
this.$$search[search] = paramValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$$compose();
|
this.$$compose();
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,35 @@ describe('$location', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('search() should handle multiple value', function() {
|
||||||
|
url.search('a&b');
|
||||||
|
expect(url.search()).toEqual({a: true, b: true});
|
||||||
|
|
||||||
|
url.search('a', null);
|
||||||
|
|
||||||
|
expect(url.search()).toEqual({b: true});
|
||||||
|
|
||||||
|
url.search('b', undefined);
|
||||||
|
expect(url.search()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('search() should handle single value', function() {
|
||||||
|
url.search('ignore');
|
||||||
|
expect(url.search()).toEqual({ignore: true});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('search() should throw error an incorrect argument', function() {
|
||||||
|
expect(function() {
|
||||||
|
url.search(null);
|
||||||
|
}).toThrow('[$location:wpt] First parameter of function must be string or an object.');
|
||||||
|
expect(function() {
|
||||||
|
url.search(undefined);
|
||||||
|
}).toThrow('[$location:wpt] First parameter of function must be string or an object.');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('hash() should change hash fragment', function() {
|
it('hash() should change hash fragment', function() {
|
||||||
url.hash('new-hash');
|
url.hash('new-hash');
|
||||||
expect(url.hash()).toBe('new-hash');
|
expect(url.hash()).toBe('new-hash');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue