Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkRenderer always adding rel="noopener noreferrer" when opening in new window #992

Closed
joelclermont opened this issue Aug 29, 2023 · 4 comments · Fixed by #993
Closed
Assignees
Labels
bug Something isn't working right

Comments

@joelclermont
Copy link

Version(s) affected

2.4.0

Description

When an external link is set to open in a new window, the noopener and noreferrer values are being added, even though my config has disabled them.

How to reproduce

Here is my setup

        $config = [
            'external_link' => [
                'internal_hosts' => ['my-internal-domain.com'],
                'open_in_new_window' => true,
                'nofollow' => '',
                'noopener' => '',
                'noreferrer' => '',
            ],
        ];

        $converter = new GithubFlavoredMarkdownConverter($config);
        $converter->getEnvironment()->addExtension(new ExternalLinkExtension());

        $converter->getEnvironment()->addRenderer(FencedCode::class, new FencedCodeRenderer());
        $converter->getEnvironment()->addRenderer(IndentedCode::class, new IndentedCodeRenderer());

Markdown input:

This is an external link [Google](https://google.com/).

HTML output:

<a target="_blank" href="https://google.com/" rel="noopener noreferrer">Google</a>

Expected output:

<a target="_blank" href="https://goggle.com/">Google</a>
@joelclermont
Copy link
Author

And if I change the config for open_in_new_window to false, the rel attribute is not rendered (as expected).

@colinodell
Copy link
Member

It looks like this is happening because LinkRenderer adds a default rel attribute if none is set:

if (isset($attrs['target']) && $attrs['target'] === '_blank' && ! isset($attrs['rel'])) {
$attrs['rel'] = 'noopener noreferrer';
}

Making ExternalLinkProcessor set the rel attribute to false should prevent this. I'll get a PR together for this shortly :)

@colinodell colinodell self-assigned this Aug 30, 2023
@colinodell colinodell added the bug Something isn't working right label Aug 30, 2023
@colinodell colinodell changed the title ExtenalLinkExtension always adding rel="noopener noreferrer" when opening in new window LinkRenderer always adding rel="noopener noreferrer" when opening in new window Aug 30, 2023
@colinodell
Copy link
Member

Fixed in v2.4.1 :)

@joelclermont
Copy link
Author

Beautiful!! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants