mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
committed by
Jeff Cross
parent
b01a03c1b9
commit
adb5c6d6cc
@@ -413,10 +413,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;
|
||||
}),
|
||||
|
||||
@@ -471,7 +472,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
|
||||
@@ -508,10 +510,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
|
||||
|
||||
@@ -136,6 +136,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');
|
||||
@@ -176,6 +181,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});
|
||||
@@ -192,6 +204,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});
|
||||
});
|
||||
|
||||
|
||||
@@ -212,6 +226,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