mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-08 17:10:06 +08:00
fix($location): don't call toString on null values
This commit is contained in:
@@ -391,7 +391,7 @@ LocationHashbangInHtml5Url.prototype =
|
||||
* @return {string} path
|
||||
*/
|
||||
path: locationGetterSetter('$$path', function(path) {
|
||||
path = path.toString();
|
||||
path = path ? path.toString() : '';
|
||||
return path.charAt(0) == '/' ? path : '/' + path;
|
||||
}),
|
||||
|
||||
@@ -488,7 +488,7 @@ LocationHashbangInHtml5Url.prototype =
|
||||
* @return {string} hash
|
||||
*/
|
||||
hash: locationGetterSetter('$$hash', function(hash) {
|
||||
return hash.toString();
|
||||
return hash ? hash.toString() : '';
|
||||
}),
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,6 +93,14 @@ describe('$location', function() {
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/1?search=a&b=c&d#hash');
|
||||
});
|
||||
|
||||
|
||||
it('path() should set to empty path on null value', function () {
|
||||
url.path('/foo');
|
||||
expect(url.path()).toBe('/foo');
|
||||
url.path(null);
|
||||
expect(url.path()).toBe('/');
|
||||
});
|
||||
|
||||
it('search() should accept string', function() {
|
||||
url.search('x=y&c');
|
||||
expect(url.search()).toEqual({x: 'y', c: true});
|
||||
@@ -184,6 +192,13 @@ describe('$location', function() {
|
||||
});
|
||||
|
||||
|
||||
it('hash() should accept null parameter', function() {
|
||||
url.hash(null);
|
||||
expect(url.hash()).toBe('');
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d');
|
||||
});
|
||||
|
||||
|
||||
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