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

Commit

Permalink
fix($location): allow 0 in path() and hash()
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozlowski-opensource authored and petebacondarwin committed Oct 2, 2014
1 parent 074a146 commit b8c5b87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,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;
}),

Expand Down Expand Up @@ -513,7 +513,7 @@ LocationHashbangInHtml5Url.prototype =
* @return {string} hash
*/
hash: locationGetterSetter('$$hash', function(hash) {
return hash ? hash.toString() : '';
return hash !== null ? hash.toString() : '';
}),

/**
Expand Down
10 changes: 10 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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');
Expand Down Expand Up @@ -240,6 +245,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);
Expand Down

0 comments on commit b8c5b87

Please sign in to comment.