From 4cf8c2ae92dcdcad3efc8fc96e1dbf23e1ff78d5 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Thu, 23 Apr 2020 18:57:31 +0300 Subject: [PATCH] Allow getUrlsInString() to match urls that start mid-word with a protocol --- backend/src/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/utils.ts b/backend/src/utils.ts index c1fe584c..3ab14073 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -387,7 +387,10 @@ export async function findRelevantAuditLogEntry( } } -const urlRegex = /(\S+\.\S+)/g; +const realLinkRegex = /https?:\/\/\S+/; // http://anything or https://anything +const plainLinkRegex = /((?!https?:\/\/)\S)+\.\S+/; // anything.anything, without http:// or https:// preceding it +// Both of the above, with precedence on the first one +const urlRegex = new RegExp(`(${realLinkRegex.source}|${plainLinkRegex.source})`, "g"); const protocolRegex = /^[a-z]+:\/\//; interface MatchedURL extends url.URL {