Linkify URLs containing @

This commit is contained in:
Ken Powers 2020-04-24 12:57:04 -04:00 committed by Scott Nonnenberg
parent d387481001
commit 980862768b
3 changed files with 26 additions and 6 deletions

View file

@ -133,6 +133,15 @@ function findLinks(text, caretLocation) {
);
}
function hasAuth(url) {
try {
const urlObject = new URL(url);
return Boolean(urlObject.username);
} catch (e) {
return null;
}
}
function getDomain(url) {
try {
const urlObject = new URL(url);
@ -215,6 +224,11 @@ function assembleChunks(chunkDescriptors) {
const ASCII_PATTERN = new RegExp('[\\u0000-\\u007F]', 'g');
function isLinkSneaky(link) {
// Any links which contain auth are considered sneaky
if (hasAuth(link)) {
return true;
}
const domain = getDomain(link);
// If the domain is falsy, something fishy is going on
if (!domain) {