mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-16 22:30:36 +08:00
fix($location): allow 0 in path() and hash()
This commit is contained in:
committed by
Peter Bacon Darwin
parent
07d62426f6
commit
f807d7ab4e
@@ -391,7 +391,7 @@ LocationHashbangInHtml5Url.prototype =
|
||||
* @return {string} path
|
||||
*/
|
||||
path: locationGetterSetter('$$path', function(path) {
|
||||
path = path ? path.toString() : '';
|
||||
path = path !== null ? path.toString() : '';
|
||||
return path.charAt(0) == '/' ? path : '/' + path;
|
||||
}),
|
||||
|
||||
@@ -488,7 +488,7 @@ LocationHashbangInHtml5Url.prototype =
|
||||
* @return {string} hash
|
||||
*/
|
||||
hash: locationGetterSetter('$$hash', function(hash) {
|
||||
return hash ? hash.toString() : '';
|
||||
return hash !== null ? hash.toString() : '';
|
||||
}),
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,6 +93,11 @@ describe('$location', function() {
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/1?search=a&b=c&d#hash');
|
||||
});
|
||||
|
||||
it('path() should allow using 0 as path', function() {
|
||||
url.path(0);
|
||||
expect(url.path()).toBe('/0');
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/0?search=a&b=c&d#hash');
|
||||
});
|
||||
|
||||
it('path() should set to empty path on null value', function () {
|
||||
url.path('/foo');
|
||||
@@ -191,6 +196,11 @@ describe('$location', function() {
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#5');
|
||||
});
|
||||
|
||||
it('hash() should allow using 0', function() {
|
||||
url.hash(0);
|
||||
expect(url.hash()).toBe('0');
|
||||
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#0');
|
||||
});
|
||||
|
||||
it('hash() should accept null parameter', function() {
|
||||
url.hash(null);
|
||||
|
||||
Reference in New Issue
Block a user