Don't linkify invalid URLs

This commit is contained in:
Ken Powers 2020-02-19 16:14:18 -05:00 committed by Scott Nonnenberg
parent 9fc127f063
commit f0028a5cfe
2 changed files with 30 additions and 2 deletions

View file

@ -216,9 +216,17 @@ const ASCII_PATTERN = new RegExp('[\\u0000-\\u007F]', 'g');
function isLinkSneaky(link) {
const domain = getDomain(link);
// If the domain is falsy, something fishy is going on
if (!domain) {
return true;
}
// This is necesary because getDomain returns domains in punycode form. We check whether
// it's available for the StyleGuide.
// Domains cannot contain encoded characters
if (domain.includes('%')) {
return true;
}
// This is necesary because getDomain returns domains in punycode form.
const unicodeDomain = nodeUrl.domainToUnicode
? nodeUrl.domainToUnicode(domain)
: domain;