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

fix($location): don't rewrite when link is shift-clicked #9906

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
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ function $LocationProvider() {
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
// currently we open nice url link and redirect then

if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.which == 2) return;
if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.shiftKey || event.which == 2) return;

var elm = jqLite(event.target);

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


it('should not rewrite when clicked with shift pressed', function() {
configureService({linkHref: 'base/a?b=c', html5Mode: true, supportHist: true});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @tbosch --- the other tests in this suite don't seem to be quite right. In testing, even without this fix, if linkHref was not preceded with base/, we would not rewrite anyways because we would determine the link to not be within the app url. So I think something is a bit wrong with these tests.

However, with the test written like this, without the fix we fail and with we pass.

inject(
initBrowser(),
initLocation(),
function($browser) {
browserTrigger(link, 'click', { keys: ['shift'] });
expectNoRewrite($browser);
}
);
});


it('should not mess up hash urls when clicking on links in hashbang mode', function() {
var base;
module(function() {
Expand Down