From e3052e8c825da699162ea25367e860ac3c66f461 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:17:10 +0100 Subject: [bugfix] Don't return Account or Status if new and dereferencing failed, other small fixes (#2563) * tidy up account, status, webfingering logic a wee bit * go fmt * invert published check * alter resp initialization * get Published from account in typeutils * don't instantiate error for no darn good reason * shadow err * don't repeat error codes in wrapped errors * don't wrap error unnecessarily --- internal/uris/uri.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'internal/uris') diff --git a/internal/uris/uri.go b/internal/uris/uri.go index ca98b6416..d12e24fea 100644 --- a/internal/uris/uri.go +++ b/internal/uris/uri.go @@ -248,6 +248,11 @@ func IsUserPath(id *url.URL) bool { return regexes.UserPath.MatchString(id.Path) } +// IsUserWebPath returns true if the given URL path corresponds to eg /@example_username +func IsUserWebPath(id *url.URL) bool { + return regexes.UserWebPath.MatchString(id.Path) +} + // IsInboxPath returns true if the given URL path corresponds to eg /users/example_username/inbox func IsInboxPath(id *url.URL) bool { return regexes.InboxPath.MatchString(id.Path) @@ -326,6 +331,17 @@ func ParseUserPath(id *url.URL) (username string, err error) { return } +// ParseUserPath returns the username from a path such as /@example_username +func ParseUserWebPath(id *url.URL) (username string, err error) { + matches := regexes.UserWebPath.FindStringSubmatch(id.Path) + if len(matches) != 2 { + err = fmt.Errorf("expected 2 matches but matches length was %d", len(matches)) + return + } + username = matches[1] + return +} + // ParseInboxPath returns the username from a path such as /users/example_username/inbox func ParseInboxPath(id *url.URL) (username string, err error) { matches := regexes.InboxPath.FindStringSubmatch(id.Path) -- cgit v1.3