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

Commit

Permalink
fix($location): don't rewrite links to different base paths
Browse files Browse the repository at this point in the history
links to different base paths should not be left untouched
  • Loading branch information
Thibault Leruitte authored and IgorMinar committed Apr 12, 2012
1 parent 7c430c5 commit 0a5050e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ function $LocationProvider(){
var href = elm.attr('href');
if (!href || isDefined(elm.attr('ng-ext-link')) || elm.attr('target')) return;

// link to different base path
if (href[0] === '/' && href.indexOf(pathPrefix) !== 0) return;

// remove same domain from full url links (IE7 always returns full hrefs)
href = href.replace(absUrlPrefix, '');

Expand Down
82 changes: 82 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,88 @@ describe('$location', function() {
});


it('should not rewrite when link to different base path when history enabled on new browser',
function() {
configureService('/other_base/link', true, true);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should not rewrite when link to different base path when history enabled on old browser',
function() {
configureService('/other_base/link', true, false);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should not rewrite when link to different base path when history disabled', function() {
configureService('/other_base/link', false);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should not rewrite when full link to different base path when history enabled on new browser',
function() {
configureService('http://host.com/other_base/link', true, true);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should not rewrite when full link to different base path when history enabled on old browser',
function() {
configureService('http://host.com/other_base/link', true, false);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should not rewrite when full link to different base path when history disabled', function() {
configureService('http://host.com/other_base/link', false);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


// don't run next tests on IE<9, as browserTrigger does not simulate pressed keys
if (!(msie < 9)) {

Expand Down

0 comments on commit 0a5050e

Please sign in to comment.