diff --git a/src/ng/location.js b/src/ng/location.js index a993757d5688..40b7c858f553 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -350,8 +350,8 @@ var locationPrototype = { return this.$$url; var match = PATH_MATCH.exec(url); - if (match[1]) this.path(decodeURIComponent(match[1])); - if (match[2] || match[1]) this.search(match[3] || ''); + if (match[1] || url === '') this.path(decodeURIComponent(match[1])); + if (match[2] || match[1] || url === '') this.search(match[3] || ''); this.hash(match[5] || ''); return this; diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 5a338729cf00..3a5c2ada06a8 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -304,6 +304,14 @@ describe('$location', function() { expect(url.hash()).toBe(''); }); + it('url() should change path when empty string specified', function() { + url.url(''); + + expect(url.path()).toBe('/'); + expect(url.search()).toEqual({}); + expect(url.hash()).toBe(''); + }); + it('replace should set $$replace flag and return itself', function() { expect(url.$$replace).toBe(false);