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

Commit

Permalink
fix($location): rewrite relative URI correctly if path==='/' in legac…
Browse files Browse the repository at this point in the history
…y html5Mode

Currently, legacy browsers get to use a clever scheme for resolving relative URIs in html5Mode,
and resolve the URI relative to $location.path().

Currently, $location.path() can be '/' under certain circumstances, which means that when we
split $location.path() on '/' and later join by '/' after adding another path component,
we end up with '//pathComponent'. $$rewrite fails to deal with this correctly, and effectively
the $location is never changed from the root path.

This CL corrects this by ensuring that the duplicate '/' situation does not occur when resolving
relative URIs.

Closes #8684
  • Loading branch information
caitp committed Aug 20, 2014
1 parent f02f7d9 commit d18b281
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ function $LocationProvider(){
// relative path - join with current path
var stack = $location.path().split("/"),
parts = href.split("/");
if (stack.length === 2 && !stack[1]) stack.length = 1;
for (var i=0; i<parts.length; i++) {
if (parts[i] == ".")
continue;
Expand Down
14 changes: 14 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,20 @@ describe('$location', function() {
});


it('should produce relative paths correctly when $location.path() is "/" when history enabled on old browser', function() {
configureService('partial1', true, false, true);
inject(
initBrowser(),
initLocation(),
function($browser, $location) {
$location.path('/');
browserTrigger(link, 'click');
expectRewriteTo($browser, 'http://host.com/base/index.html#!/partial1');
}
);
});


it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
configureService('/base/link?a#b', true, false);
inject(
Expand Down

0 comments on commit d18b281

Please sign in to comment.