Skip to content

Commit c8b0b57

Browse files
committed
chore: handle path escaping, tildes in GitHub releases
1 parent 6dc30fb commit c8b0b57

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net/url"
1313
"os"
1414
"path"
15+
"strings"
1516
"sync"
1617
"time"
1718

@@ -124,7 +125,6 @@ func (r *githubRedirector) Serve(ctx context.Context) error {
124125
if err != nil {
125126
return err
126127
}
127-
slog.Info("loaded GitHub assets", "count", len(assets))
128128
r.mut.Lock()
129129
r.assets = assets
130130
r.mut.Unlock()
@@ -137,16 +137,23 @@ func (r *githubRedirector) Serve(ctx context.Context) error {
137137

138138
func (r *githubRedirector) ServeHTTP(w http.ResponseWriter, req *http.Request) {
139139
file := path.Base(req.URL.Path)
140+
if unesc, err := url.PathUnescape(file); err == nil {
141+
file = unesc
142+
}
143+
140144
r.mut.Lock()
141145
url, ok := r.assets[file]
146+
// Special case; tildes become dots in GitHub assets...
147+
if !ok {
148+
url, ok = r.assets[strings.Replace(file, "~", ".", 1)]
149+
}
142150
r.mut.Unlock()
151+
143152
if ok {
144-
slog.Info("serving redirect", "from", req.URL, "to", url)
145153
http.Redirect(w, req, url, http.StatusTemporaryRedirect)
146154
return
147155
}
148156

149-
slog.Info("serving direct", "url", req.URL)
150157
r.next.ServeHTTP(w, req)
151158
}
152159

0 commit comments

Comments
 (0)