From 4c92782c3a4916b3cd8119da0bd6fd1574a8b0d5 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Fri, 9 Jun 2023 06:34:45 -0700 Subject: [PATCH] Simplify url regex --- src/util/nostr.ts | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/util/nostr.ts b/src/util/nostr.ts index 596451ac..d5113d0a 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -263,11 +263,7 @@ export const parseContent = ({content, tags = []}) => { } const parseUrl = () => { - const raw = first( - text.match( - /^((http|ws)s?:\/\/)?[-a-z0-9:%_\+~#@,=\.\*\(\)]+\.[a-z]{1,6}[-a-z0-9:%_\+~#\?&\/=;#@,\.\(\)]*/gi - ) - ) + const raw = first(text.match(/^([a-z\+:]{2,30}:\/\/)?[^\s]+\.[a-z]{2,6}[^\s]*[^\.!?,:\s]/gi)) // Skip url if it's just the end of a filepath if (raw) { @@ -280,18 +276,15 @@ export const parseContent = ({content, tags = []}) => { let url = raw // Skip ellipses and very short non-urls - if (!url.match(/\.\./) && url.length > 4) { - // It's common for punctuation to end a url, trim it off - if (url.match(/[\.\?,:]$/)) { - url = url.slice(0, -1) - } - - if (!url.match("://")) { - url = "https://" + url - } - - return ["link", raw, url] + if (url.match(/\.\./)) { + return } + + if (!url.match("://")) { + url = "https://" + url + } + + return ["link", raw, url] } }