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

Commit c6e4def

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 74a7afc commit c6e4def

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
@@ -954,6 +954,20 @@ describe('$location', function() {
954954
});
955955

956956

957+
it('should produce relative paths correctly when $location.path() is "/" when history enabled on old browser', function() {
958+
configureService('partial1', true, false, true);
959+
inject(
960+
initBrowser(),
961+
initLocation(),
962+
function($browser, $location) {
963+
$location.path('/');
964+
browserTrigger(link, 'click');
965+
expectRewriteTo($browser, 'http://host.com/base/index.html#!/partial1');
966+
}
967+
);
968+
});
969+
970+
957971
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
958972
configureService('/base/link?a#b', true, false);
959973
inject(

0 commit comments

Comments
 (0)