diff --git a/golink.go b/golink.go index 03ef723..151b3d2 100644 --- a/golink.go +++ b/golink.go @@ -527,6 +527,15 @@ func serveGo(w http.ResponseWriter, r *http.Request) { } link, err := db.Load(short) + if errors.Is(err, fs.ErrNotExist) { + // Trim common punctuation from the end and try again. + // This catches auto-linking and copy/paste issues that include punctuation. + if s := strings.TrimRight(short, ".,()[]{}"); short != s { + short = s + link, err = db.Load(short) + } + } + if errors.Is(err, fs.ErrNotExist) { w.WriteHeader(http.StatusNotFound) serveHome(w, r, short) diff --git a/golink_test.go b/golink_test.go index 564a56b..12c0263 100644 --- a/golink_test.go +++ b/golink_test.go @@ -75,6 +75,31 @@ func TestServeGo(t *testing.T) { wantStatus: http.StatusFound, wantLink: "http://who/http://host", }, + { + name: "simple link, trailing period", + link: "/who.", + wantStatus: http.StatusFound, + wantLink: "http://who/", + }, + { + name: "simple link, trailing comma", + link: "/who,", + wantStatus: http.StatusFound, + wantLink: "http://who/", + }, + { + // This seems like an incredibly unlikely typo, but test it anyway. + name: "simple link, trailing comma and path", + link: "/who,/p", + wantStatus: http.StatusFound, + wantLink: "http://who/p", + }, + { + name: "simple link, trailing paren", + link: "/who)", + wantStatus: http.StatusFound, + wantLink: "http://who/", + }, { name: "user link", link: "/me",