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

fix($location) don't rewrite location when clicking on "javascript:" or "mailto:" link #8426

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ function $LocationProvider(){
$location = new LocationMode(appBase, '#' + hashPrefix);
$location.$$parse($location.$$rewrite(initialUrl));

var IGNORE_URI_REGEXP = /^\s*(javascript|mailto):/i;

$rootElement.on('click', function(event) {
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
// currently we open nice url link and redirect then
Expand All @@ -657,6 +659,9 @@ function $LocationProvider(){
absHref = urlResolve(absHref.animVal).href;
}

// Ignore when url is started with javascript: or mailto:
if (IGNORE_URI_REGEXP.test(absHref)) return;

// Make relative links work in HTML5 mode for legacy browsers (or at least IE8 & 9)
// The href should be a regular url e.g. /link/somewhere or link/somewhere or ../somewhere or
// somewhere#anchor or http://example.com/somewhere
Expand Down
26 changes: 26 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,32 @@ describe('$location', function() {
});


it('should not rewrite links with `javascript:` URI', function() {
configureService(' jAvAsCrIpT:throw new Error("Boom!")', true, true, true);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should not rewrite links with `mailto:` URI', function() {
configureService(' mAiLtO:[email protected]', true, true, true);
inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click');
expectNoRewrite($browser);
}
);
});


it('should rewrite full url links to same domain and base path', function() {
configureService('http://host.com/base/new', true);
inject(
Expand Down