Don't linkify invalid URLs
This commit is contained in:

committed by
Scott Nonnenberg

parent
9fc127f063
commit
f0028a5cfe
@@ -216,9 +216,17 @@ const ASCII_PATTERN = new RegExp('[\\u0000-\\u007F]', 'g');
|
|||||||
|
|
||||||
function isLinkSneaky(link) {
|
function isLinkSneaky(link) {
|
||||||
const domain = getDomain(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
|
// Domains cannot contain encoded characters
|
||||||
// it's available for the StyleGuide.
|
if (domain.includes('%')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is necesary because getDomain returns domains in punycode form.
|
||||||
const unicodeDomain = nodeUrl.domainToUnicode
|
const unicodeDomain = nodeUrl.domainToUnicode
|
||||||
? nodeUrl.domainToUnicode(domain)
|
? nodeUrl.domainToUnicode(domain)
|
||||||
: domain;
|
: domain;
|
||||||
|
@@ -371,5 +371,25 @@ describe('Link previews', () => {
|
|||||||
const actual = isLinkSneaky(link);
|
const actual = isLinkSneaky(link);
|
||||||
assert.strictEqual(actual, true);
|
assert.strictEqual(actual, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns true for =', () => {
|
||||||
|
const link = 'r.id=s.id';
|
||||||
|
assert.strictEqual(isLinkSneaky(link), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true for $', () => {
|
||||||
|
const link = 'r.id$s.id';
|
||||||
|
assert.strictEqual(isLinkSneaky(link), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true for +', () => {
|
||||||
|
const link = 'r.id+s.id';
|
||||||
|
assert.strictEqual(isLinkSneaky(link), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true for ^', () => {
|
||||||
|
const link = 'r.id^s.id';
|
||||||
|
assert.strictEqual(isLinkSneaky(link), true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user