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

Commit d18b281

Browse files
committed
fix($location): rewrite relative URI correctly if path==='/' in legacy 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
1 parent f02f7d9 commit d18b281

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/ng/location.js

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ function $LocationProvider(){
682682
// relative path - join with current path
683683
var stack = $location.path().split("/"),
684684
parts = href.split("/");
685+
if (stack.length === 2 && !stack[1]) stack.length = 1;
685686
for (var i=0; i<parts.length; i++) {
686687
if (parts[i] == ".")
687688
continue;

test/ng/locationSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,20 @@ describe('$location', function() {
996996
});
997997

998998

999+
it('should produce relative paths correctly when $location.path() is "/" when history enabled on old browser', function() {
1000+
configureService('partial1', true, false, true);
1001+
inject(
1002+
initBrowser(),
1003+
initLocation(),
1004+
function($browser, $location) {
1005+
$location.path('/');
1006+
browserTrigger(link, 'click');
1007+
expectRewriteTo($browser, 'http://host.com/base/index.html#!/partial1');
1008+
}
1009+
);
1010+
});
1011+
1012+
9991013
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
10001014
configureService('/base/link?a#b', true, false);
10011015
inject(

0 commit comments

Comments
 (0)