diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-08-01 17:48:11 +0200 |
---|---|---|
committer | ThibG <thib@sitedethib.com> | 2019-08-04 22:25:56 +0200 |
commit | 43b137e1f91a5cbe42e16b9cc9db7fdbe5d01099 (patch) | |
tree | 76e9c6f58d844389d80edcf790a985854bed481d | |
parent | a0b6f1665aa8fca838dfbcf08bf66d1b36a94c05 (diff) |
Perform case-insensitive comparison of non-International domain names
-rw-r--r-- | app/javascript/flavours/glitch/components/status_content.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/components/status_content.js b/app/javascript/flavours/glitch/components/status_content.js index 1aaadb632..e51cc8fd5 100644 --- a/app/javascript/flavours/glitch/components/status_content.js +++ b/app/javascript/flavours/glitch/components/status_content.js @@ -25,6 +25,12 @@ const dot_confusables = '.\u002e\u0660\u06f0\u0701\u0702\u2024\ua4f8\ua60e\u10a5 const linkRegex = new RegExp(`^\\s*(([${h_confusables}][${t_confusables}][${t_confusables}][${p_confusables}][${s_confusables}]?[${column_confusables}][${slash_confusables}][${slash_confusables}]))?[^:/\\n ]+([${dot_confusables}][^:/\\n ]+)+`); +const textMatchesTarget = (text, origin, host) => { + return (text === origin || text === host + || text.startsWith(origin + '/') || text.startsWith(host + '/') + || 'www.' + text === host || ('www.' + text).startsWith(host + '/')); +} + // If `checkUrlLike` is true, consider only URL-like link texts to be misleading const isLinkMisleading = (link, checkUrlLike = true) => { let linkTextParts = []; @@ -54,7 +60,7 @@ const isLinkMisleading = (link, checkUrlLike = true) => { const targetURL = new URL(link.href); // The following may not work with international domain names - if (linkText === targetURL.origin || linkText === targetURL.host || 'www.' + linkText === targetURL.host || linkText.startsWith(targetURL.origin + '/') || linkText.startsWith(targetURL.host + '/') || ('www.' + linkText).startsWith(targetURL.host + '/')) { + if (textMatchesTarget(linkText, targetURL.origin, targetURL.host) || textMatchesTarget(linkText.toLowerCase(), targetURL.origin, targetURL.host)) { return false; } @@ -62,7 +68,7 @@ const isLinkMisleading = (link, checkUrlLike = true) => { const hostname = decodeIDNA(targetURL.hostname); const host = targetURL.host.replace(targetURL.hostname, hostname); const origin = targetURL.origin.replace(targetURL.host, host); - if (linkText === origin || linkText === host || 'www.' + linkText === host || linkText.startsWith(origin + '/') || linkText.startsWith(host + '/') || ('www.' + linkText).startsWith(host + '/')) { + if (textMatchesTarget(linkText, origin, host)) { return false; } |