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

Commit b8c5b87

Browse files
fix($location): allow 0 in path() and hash()
1 parent 074a146 commit b8c5b87

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
@@ -416,7 +416,7 @@ LocationHashbangInHtml5Url.prototype =
416416
* @return {string} path
417417
*/
418418
path: locationGetterSetter('$$path', function(path) {
419-
path = path ? path.toString() : '';
419+
path = path !== null ? path.toString() : '';
420420
return path.charAt(0) == '/' ? path : '/' + path;
421421
}),
422422

@@ -513,7 +513,7 @@ LocationHashbangInHtml5Url.prototype =
513513
* @return {string} hash
514514
*/
515515
hash: locationGetterSetter('$$hash', function(hash) {
516-
return hash ? hash.toString() : '';
516+
return hash !== null ? hash.toString() : '';
517517
}),
518518

519519
/**

test/ng/locationSpec.js

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

145+
it('path() should allow using 0 as path', function() {
146+
url.path(0);
147+
expect(url.path()).toBe('/0');
148+
expect(url.absUrl()).toBe('http://www.domain.com:9877/0?search=a&b=c&d#hash');
149+
});
145150

146151
it('path() should set to empty path on null value', function () {
147152
url.path('/foo');
@@ -240,6 +245,11 @@ describe('$location', function() {
240245
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#5');
241246
});
242247

248+
it('hash() should allow using 0', function() {
249+
url.hash(0);
250+
expect(url.hash()).toBe('0');
251+
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#0');
252+
});
243253

244254
it('hash() should accept null parameter', function() {
245255
url.hash(null);

0 commit comments

Comments
 (0)