Skip to content

Commit

Permalink
fix($location): links without path segment should not change the path
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Nov 10, 2011
1 parent e4303a1 commit db170a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/service/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ LocationUrl.prototype = LocationHashbangUrl.prototype = {
return this.$$url;

var match = PATH_MATCH.exec(url);
this.path(decodeURIComponent(match[1] || '')).search(match[3] || '')
.hash(match[5] || '', replace);
if (match[1]) this.path(decodeURIComponent(match[1]));
if (match[2] || match[1]) this.search(match[3] || '');
this.hash(match[5] || '', replace);

return this;
},
Expand Down
27 changes: 27 additions & 0 deletions test/service/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ describe('$location', function() {
});


it('url() should change only hash when no search and path specified', function() {
url.url('#some-hash');

expect(url.hash()).toBe('some-hash');
expect(url.url()).toBe('/path/b?search=a&b=c&d#some-hash');
expect(url.absUrl()).toBe('http://www.domain.com:9877/path/b?search=a&b=c&d#some-hash');
});


it('url() should change only search and hash when no path specified', function() {
url.url('?a=b');

expect(url.search()).toEqual({a: 'b'});
expect(url.hash()).toBe('');
expect(url.path()).toBe('/path/b');
});


it('url() should reset search and hash even when only path specified', function() {
url.url('/new/path');

expect(url.path()).toBe('/new/path');
expect(url.search()).toEqual({});
expect(url.hash()).toBe('');
});


it('replace should set $$replace flag and return itself', function() {
expect(url.$$replace).toBe(false);

Expand Down

0 comments on commit db170a9

Please sign in to comment.