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

Commit 0a5050e

Browse files
Thibault LeruitteIgorMinar
Thibault Leruitte
authored andcommitted
fix($location): don't rewrite links to different base paths
links to different base paths should not be left untouched
1 parent 7c430c5 commit 0a5050e

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/ng/location.js

+3
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ function $LocationProvider(){
503503
var href = elm.attr('href');
504504
if (!href || isDefined(elm.attr('ng-ext-link')) || elm.attr('target')) return;
505505

506+
// link to different base path
507+
if (href[0] === '/' && href.indexOf(pathPrefix) !== 0) return;
508+
506509
// remove same domain from full url links (IE7 always returns full hrefs)
507510
href = href.replace(absUrlPrefix, '');
508511

test/ng/locationSpec.js

+82
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,88 @@ describe('$location', function() {
864864
});
865865

866866

867+
it('should not rewrite when link to different base path when history enabled on new browser',
868+
function() {
869+
configureService('/other_base/link', true, true);
870+
inject(
871+
initBrowser(),
872+
initLocation(),
873+
function($browser) {
874+
browserTrigger(link, 'click');
875+
expectNoRewrite($browser);
876+
}
877+
);
878+
});
879+
880+
881+
it('should not rewrite when link to different base path when history enabled on old browser',
882+
function() {
883+
configureService('/other_base/link', true, false);
884+
inject(
885+
initBrowser(),
886+
initLocation(),
887+
function($browser) {
888+
browserTrigger(link, 'click');
889+
expectNoRewrite($browser);
890+
}
891+
);
892+
});
893+
894+
895+
it('should not rewrite when link to different base path when history disabled', function() {
896+
configureService('/other_base/link', false);
897+
inject(
898+
initBrowser(),
899+
initLocation(),
900+
function($browser) {
901+
browserTrigger(link, 'click');
902+
expectNoRewrite($browser);
903+
}
904+
);
905+
});
906+
907+
908+
it('should not rewrite when full link to different base path when history enabled on new browser',
909+
function() {
910+
configureService('http://host.com/other_base/link', true, true);
911+
inject(
912+
initBrowser(),
913+
initLocation(),
914+
function($browser) {
915+
browserTrigger(link, 'click');
916+
expectNoRewrite($browser);
917+
}
918+
);
919+
});
920+
921+
922+
it('should not rewrite when full link to different base path when history enabled on old browser',
923+
function() {
924+
configureService('http://host.com/other_base/link', true, false);
925+
inject(
926+
initBrowser(),
927+
initLocation(),
928+
function($browser) {
929+
browserTrigger(link, 'click');
930+
expectNoRewrite($browser);
931+
}
932+
);
933+
});
934+
935+
936+
it('should not rewrite when full link to different base path when history disabled', function() {
937+
configureService('http://host.com/other_base/link', false);
938+
inject(
939+
initBrowser(),
940+
initLocation(),
941+
function($browser) {
942+
browserTrigger(link, 'click');
943+
expectNoRewrite($browser);
944+
}
945+
);
946+
});
947+
948+
867949
// don't run next tests on IE<9, as browserTrigger does not simulate pressed keys
868950
if (!(msie < 9)) {
869951

0 commit comments

Comments
 (0)