Skip to content

Commit

Permalink
fix(i18n-sanitize): handle cases where origin equals empty string
Browse files Browse the repository at this point in the history
This fixes an issue with Chrome > 120.

Fixes #906
  • Loading branch information
florian-sanders-cc committed Dec 11, 2023
1 parent 4ad2303 commit 0852482
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/i18n-sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export function sanitize (statics, ...params) {
// If link has href and external origin => force rel and target
if (node.tagName === 'A' && node.getAttribute('href') != null) {
node.classList.add('sanitized-link');
if (node.origin !== window.location.origin) {
// Chrome > 120 returns an empty string for an anchor element with an absolute url like `href=/foo` when it's in a template DOM element
// In such case, we need to test if it's an empty string to make sure absolute or relative urls are not considered external
if (node.origin?.length > 0 && node.origin !== window.location.origin) {
node.setAttribute('rel', 'noopener noreferrer');
node.setAttribute('target', '_blank');
}
Expand Down

0 comments on commit 0852482

Please sign in to comment.