Skip to content

Commit

Permalink
Merge branch 'tailscale:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
stepbrobd authored Jan 11, 2025
2 parents b692e31 + c21529a commit c128ed6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions golink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions golink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c128ed6

Please sign in to comment.