fix($location): allow 0 in path() and hash()

This commit is contained in:
Pawel Kozlowski
2014-09-12 20:16:33 +02:00
committed by Peter Bacon Darwin
parent 07d62426f6
commit f807d7ab4e
2 changed files with 12 additions and 2 deletions

View File

@@ -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() : '';
}),
/**

View File

@@ -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);