greenpeace / planet4

Built on top of Wordpress tech, Greenpeace Planet 4 powers digital platforms to engage with millions and win campaigns around the world.
https://planet4.greenpeace.org
Creative Commons Attribution Share Alike 4.0 International
66 stars 27 forks source link

PLANET-5444 target="_blank" gets added to links that aren't external #78

Closed stduerre closed 4 years ago

stduerre commented 4 years ago

Where did you find the bug?

Every link in content that has href="javascript:void(0)", which is a common way to prevent default link behavior. Example here: https://develop.greenpeace.ch/de/external-link/

What went wrong?

A link that isn't to an external page is treated as external link. Functionality is broken (it opens in a new tab) and formatting is wrong (external link icon is added to it).

Here's the problem:

Links that don't conform to a certain pattern are changed to be formatted as external links (by adding an svg icon and a class name) and target="_blank" gets added the them. The function that does this is greedy and doesn't exclude this case. In this case, the link should not be treated as an external link.

stduerre commented 4 years ago

Relevant code: https://github.com/greenpeace/planet4-master-theme/blob/e28a5e14eda1b3c3da7a93c821b0ef9daf7a2d72/assets/src/js/external_links.js#L20