File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -527,6 +527,15 @@ func serveGo(w http.ResponseWriter, r *http.Request) {
527
527
}
528
528
529
529
link , err := db .Load (short )
530
+ if errors .Is (err , fs .ErrNotExist ) {
531
+ // Trim common punctuation from the end and try again.
532
+ // This catches auto-linking and copy/paste issues that include punctuation.
533
+ if s := strings .TrimRight (short , ".,()[]{}" ); short != s {
534
+ short = s
535
+ link , err = db .Load (short )
536
+ }
537
+ }
538
+
530
539
if errors .Is (err , fs .ErrNotExist ) {
531
540
w .WriteHeader (http .StatusNotFound )
532
541
serveHome (w , r , short )
Original file line number Diff line number Diff line change @@ -75,6 +75,31 @@ func TestServeGo(t *testing.T) {
75
75
wantStatus : http .StatusFound ,
76
76
wantLink : "http://who/http://host" ,
77
77
},
78
+ {
79
+ name : "simple link, trailing period" ,
80
+ link : "/who." ,
81
+ wantStatus : http .StatusFound ,
82
+ wantLink : "http://who/" ,
83
+ },
84
+ {
85
+ name : "simple link, trailing comma" ,
86
+ link : "/who," ,
87
+ wantStatus : http .StatusFound ,
88
+ wantLink : "http://who/" ,
89
+ },
90
+ {
91
+ // This seems like an incredibly unlikely typo, but test it anyway.
92
+ name : "simple link, trailing comma and path" ,
93
+ link : "/who,/p" ,
94
+ wantStatus : http .StatusFound ,
95
+ wantLink : "http://who/p" ,
96
+ },
97
+ {
98
+ name : "simple link, trailing paren" ,
99
+ link : "/who)" ,
100
+ wantStatus : http .StatusFound ,
101
+ wantLink : "http://who/" ,
102
+ },
78
103
{
79
104
name : "user link" ,
80
105
link : "/me" ,
You can’t perform that action at this time.
0 commit comments