From 5c5ad19c43e0dc7c501ba60d1b6e1b2a5ecb9bc8 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Tue, 22 Oct 2024 03:48:12 +0000 Subject: [PATCH] feat: replace `xurls` third-party module with an ad-hoc regexp --- go.mod | 1 - go.sum | 2 -- internal/ui/subscription_bookmarklet.go | 8 +++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c1c4f7d23c6..d25ca7c7393 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( golang.org/x/oauth2 v0.23.0 golang.org/x/term v0.25.0 golang.org/x/text v0.19.0 - mvdan.cc/xurls/v2 v2.5.0 ) require ( diff --git a/go.sum b/go.sum index 896199cce7d..03e5ebd9309 100644 --- a/go.sum +++ b/go.sum @@ -117,5 +117,3 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -mvdan.cc/xurls/v2 v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8= -mvdan.cc/xurls/v2 v2.5.0/go.mod h1:yQgaGQ1rFtJUzkmKiHYSSfuQxqfYmd//X6PxvholpeE= diff --git a/internal/ui/subscription_bookmarklet.go b/internal/ui/subscription_bookmarklet.go index 990e6428c5d..dfc4dfd2380 100644 --- a/internal/ui/subscription_bookmarklet.go +++ b/internal/ui/subscription_bookmarklet.go @@ -5,6 +5,7 @@ package ui // import "miniflux.app/v2/internal/ui" import ( "net/http" + "regexp" "miniflux.app/v2/internal/config" "miniflux.app/v2/internal/http/request" @@ -12,10 +13,11 @@ import ( "miniflux.app/v2/internal/ui/form" "miniflux.app/v2/internal/ui/session" "miniflux.app/v2/internal/ui/view" - - "mvdan.cc/xurls/v2" ) +// Best effort url extraction regexp +var urlRe = regexp.MustCompile(`(?i)(?:https?://)?[0-9a-z.]+[.][a-z]+(?::[0-9]+)?(?:/[^ ]+|/)?`) + func (h *handler) bookmarklet(w http.ResponseWriter, r *http.Request) { user, err := h.store.UserByID(request.UserID(r)) if err != nil { @@ -39,7 +41,7 @@ func (h *handler) bookmarklet(w http.ResponseWriter, r *http.Request) { // See https://bugs.chromium.org/p/chromium/issues/detail?id=789379. text := request.QueryStringParam(r, "text", "") if text != "" && bookmarkletURL == "" { - bookmarkletURL = xurls.Relaxed().FindString(text) + bookmarkletURL = urlRe.FindString(text) } sess := session.New(h.store, request.SessionID(r))