summaryrefslogtreecommitdiff
path: root/internal/regexes/regexes.go
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2025-03-24 14:13:32 +0100
committerLibravatar GitHub <noreply@github.com>2025-03-24 14:13:32 +0100
commit1bf40e755c897dfedcfa1b54a5598475b99099d4 (patch)
tree2589cd2e5db9e73b67fdedab83355ca1d520bf77 /internal/regexes/regexes.go
parent[feature] Parse funkwhale `Album` as Statusable to allow barebones interactin... (diff)
downloadgotosocial-1bf40e755c897dfedcfa1b54a5598475b99099d4.tar.xz
feat: Relax URL matching (#3925)
* feat: Relax URL matching Instead of only linkifying things with an explicit http or https scheme, the xurls.Relaxed also matches links with known TLDs. This means that text like 'banana.com' will also be matched, despite the missing http/https scheme. This also works to linkify email addresses, which is handy. This should also ensure we catch links without a scheme for the purpose of spam checking.
Diffstat (limited to 'internal/regexes/regexes.go')
-rw-r--r--internal/regexes/regexes.go14
1 files changed, 4 insertions, 10 deletions
diff --git a/internal/regexes/regexes.go b/internal/regexes/regexes.go
index 515f69a12..a94387e47 100644
--- a/internal/regexes/regexes.go
+++ b/internal/regexes/regexes.go
@@ -22,7 +22,7 @@ import (
"regexp"
"sync"
- "mvdan.cc/xurls/v2"
+ xurls "mvdan.cc/xurls/v2"
)
const (
@@ -40,7 +40,6 @@ const (
reports = "reports"
accepts = "accepts"
- schemes = `(http|https)://` // Allowed URI protocols for parsing links in text.
alphaNumeric = `\p{L}\p{M}*|\p{N}` // A single number or script character in any language, including chars with accents.
usernameGrp = `(?:` + alphaNumeric + `|\.|\-|\_)` // Non-capturing group that matches against a single valid username character.
domainGrp = `(?:` + alphaNumeric + `|\.|\-|\:)` // Non-capturing group that matches against a single valid domain character.
@@ -79,14 +78,9 @@ const (
)
var (
- // LinkScheme captures http/https schemes in URLs.
- LinkScheme = func() *regexp.Regexp {
- rgx, err := xurls.StrictMatchingScheme(schemes)
- if err != nil {
- panic(err)
- }
- return rgx
- }()
+ // URLLike captures anything that resembles a URL. This includes URLs
+ // with or without a scheme, and emails.
+ URLLike = xurls.Relaxed()
// MentionName captures the username and domain part from
// a mention string such as @whatever_user@example.org,