From b8c5b87119a06edb8e8d1cefad81ee8d1f64f070 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 12 Sep 2014 20:16:33 +0200 Subject: [PATCH] fix($location): allow 0 in path() and hash() --- src/ng/location.js | 4 ++-- test/ng/locationSpec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ng/location.js b/src/ng/location.js index 1fcbbf13de57..5e425ab0d65a 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -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; }), @@ -513,7 +513,7 @@ LocationHashbangInHtml5Url.prototype = * @return {string} hash */ hash: locationGetterSetter('$$hash', function(hash) { - return hash ? hash.toString() : ''; + return hash !== null ? hash.toString() : ''; }), /** diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 6e43da0c1dd5..d6cf2cbeb090 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -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'); @@ -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);