Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f807d7a

Browse files
fix($location): allow 0 in path() and hash()
1 parent 07d6242 commit f807d7a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/ng/location.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ LocationHashbangInHtml5Url.prototype =
391391
* @return {string} path
392392
*/
393393
path: locationGetterSetter('$$path', function(path) {
394-
path = path ? path.toString() : '';
394+
path = path !== null ? path.toString() : '';
395395
return path.charAt(0) == '/' ? path : '/' + path;
396396
}),
397397

@@ -488,7 +488,7 @@ LocationHashbangInHtml5Url.prototype =
488488
* @return {string} hash
489489
*/
490490
hash: locationGetterSetter('$$hash', function(hash) {
491-
return hash ? hash.toString() : '';
491+
return hash !== null ? hash.toString() : '';
492492
}),
493493

494494
/**

test/ng/locationSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ describe('$location', function() {
9393
expect(url.absUrl()).toBe('http://www.domain.com:9877/1?search=a&b=c&d#hash');
9494
});
9595

96+
it('path() should allow using 0 as path', function() {
97+
url.path(0);
98+
expect(url.path()).toBe('/0');
99+
expect(url.absUrl()).toBe('http://www.domain.com:9877/0?search=a&b=c&d#hash');
100+
});
96101

97102
it('path() should set to empty path on null value', function () {
98103
url.path('/foo');
@@ -191,6 +196,11 @@ describe('$location', function() {
191196
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#5');
192197
});
193198

199+
it('hash() should allow using 0', function() {
200+
url.hash(0);
201+
expect(url.hash()).toBe('0');
202+
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#0');
203+
});
194204

195205
it('hash() should accept null parameter', function() {
196206
url.hash(null);

0 commit comments

Comments
 (0)