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

Commit c12e8d4

Browse files
committed
fix($location): don't call toString on null values
1 parent c65796d commit c12e8d4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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.toString();
394+
path = path ? 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.toString();
491+
return hash ? hash.toString() : '';
492492
}),
493493

494494
/**

test/ng/locationSpec.js

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

96+
97+
it('path() should set to empty path on null value', function () {
98+
url.path('/foo');
99+
expect(url.path()).toBe('/foo');
100+
url.path(null);
101+
expect(url.path()).toBe('/');
102+
});
103+
96104
it('search() should accept string', function() {
97105
url.search('x=y&c');
98106
expect(url.search()).toEqual({x: 'y', c: true});
@@ -184,6 +192,13 @@ describe('$location', function() {
184192
});
185193

186194

195+
it('hash() should accept null parameter', function() {
196+
url.hash(null);
197+
expect(url.hash()).toBe('');
198+
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d');
199+
});
200+
201+
187202
it('url() should change the path, search and hash', function() {
188203
url.url('/some/path?a=b&c=d#hhh');
189204
expect(url.url()).toBe('/some/path?a=b&c=d#hhh');

0 commit comments

Comments
 (0)