mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-11 10:59:24 +08:00
committed by
Jeff Cross
parent
239d0b1f49
commit
68a09ba74d
@@ -388,10 +388,11 @@ LocationHashbangInHtml5Url.prototype =
|
||||
* Note: Path should always begin with forward slash (/), this method will add the forward slash
|
||||
* if it is missing.
|
||||
*
|
||||
* @param {string=} path New path
|
||||
* @param {(string|number)=} path New path
|
||||
* @return {string} path
|
||||
*/
|
||||
path: locationGetterSetter('$$path', function(path) {
|
||||
path = path.toString();
|
||||
return path.charAt(0) == '/' ? path : '/' + path;
|
||||
}),
|
||||
|
||||
@@ -446,7 +447,8 @@ LocationHashbangInHtml5Url.prototype =
|
||||
case 0:
|
||||
return this.$$search;
|
||||
case 1:
|
||||
if (isString(search)) {
|
||||
if (isString(search) || isNumber(search)) {
|
||||
search = search.toString();
|
||||
this.$$search = parseKeyValue(search);
|
||||
} else if (isObject(search)) {
|
||||
// remove object undefined or null properties
|
||||
@@ -483,10 +485,12 @@ LocationHashbangInHtml5Url.prototype =
|
||||
*
|
||||
* Change hash fragment when called with parameter and return `$location`.
|
||||
*
|
||||
* @param {string=} hash New hash fragment
|
||||
* @param {(string|number)=} hash New hash fragment
|
||||
* @return {string} hash
|
||||
*/
|
||||
hash: locationGetterSetter('$$hash', identity),
|
||||
hash: locationGetterSetter('$$hash', function(hash) {
|
||||
return hash.toString();
|
||||
}),
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
|
||||
@@ -87,6 +87,11 @@ describe('$location', function() {
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/new/path?search=a&b=c&d#hash');
|
||||
});
|
||||
|
||||
it('path() should not break on numeric values', function() {
|
||||
url.path(1);
|
||||
expect(url.path()).toBe('/1');
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/1?search=a&b=c&d#hash');
|
||||
});
|
||||
|
||||
it('search() should accept string', function() {
|
||||
url.search('x=y&c');
|
||||
@@ -127,6 +132,13 @@ describe('$location', function() {
|
||||
});
|
||||
|
||||
|
||||
it('search() should accept numeric keys', function() {
|
||||
url.search({1: 'one', 2: 'two'});
|
||||
expect(url.search()).toEqual({'1': 'one', '2': 'two'});
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?1=one&2=two#hash');
|
||||
});
|
||||
|
||||
|
||||
it('search() should handle multiple value', function() {
|
||||
url.search('a&b');
|
||||
expect(url.search()).toEqual({a: true, b: true});
|
||||
@@ -143,6 +155,8 @@ describe('$location', function() {
|
||||
it('search() should handle single value', function() {
|
||||
url.search('ignore');
|
||||
expect(url.search()).toEqual({ignore: true});
|
||||
url.search(1);
|
||||
expect(url.search()).toEqual({1: true});
|
||||
});
|
||||
|
||||
|
||||
@@ -163,6 +177,13 @@ describe('$location', function() {
|
||||
});
|
||||
|
||||
|
||||
it('hash() should accept numeric parameter', function() {
|
||||
url.hash(5);
|
||||
expect(url.hash()).toBe('5');
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#5');
|
||||
});
|
||||
|
||||
|
||||
it('url() should change the path, search and hash', function() {
|
||||
url.url('/some/path?a=b&c=d#hhh');
|
||||
expect(url.url()).toBe('/some/path?a=b&c=d#hhh');
|
||||
|
||||
Reference in New Issue
Block a user