diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-22 11:44:59 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-22 11:44:59 +0800 |
commit | c7440c2c3366e516ef9b0f4c34093e0c7f5c23d4 (patch) | |
tree | 4695fba3ffb65a2abbadda90bac2c7511ffcaaf7 /http_handle_repo_raw.go | |
parent | Fix HTTPS cloning (diff) | |
download | forge-c7440c2c3366e516ef9b0f4c34093e0c7f5c23d4.tar.gz forge-c7440c2c3366e516ef9b0f4c34093e0c7f5c23d4.tar.zst forge-c7440c2c3366e516ef9b0f4c34093e0c7f5c23d4.zip |
Fix tree/raw redirection and disallow slashes in their path segments
Diffstat (limited to 'http_handle_repo_raw.go')
-rw-r--r-- | http_handle_repo_raw.go | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/http_handle_repo_raw.go b/http_handle_repo_raw.go index e398856..8664ceb 100644 --- a/http_handle_repo_raw.go +++ b/http_handle_repo_raw.go @@ -6,7 +6,6 @@ package main import ( "fmt" "net/http" - "path" "strings" "github.com/go-git/go-git/v5" @@ -51,8 +50,7 @@ func httpHandleRepoRaw(w http.ResponseWriter, r *http.Request, params map[string http.Error(w, "Error retrieving path: "+err.Error(), http.StatusInternalServerError) return } - if len(rawPathSpec) != 0 && rawPathSpec[len(rawPathSpec)-1] == '/' { - http.Redirect(w, r, "../"+pathSpec, http.StatusSeeOther) + if redirectNoDir(w, r) { return } if fileContent, err = file.Contents(); err != nil { @@ -64,8 +62,7 @@ func httpHandleRepoRaw(w http.ResponseWriter, r *http.Request, params map[string } } - if len(rawPathSpec) != 0 && rawPathSpec[len(rawPathSpec)-1] != '/' { - http.Redirect(w, r, path.Base(pathSpec)+"/", http.StatusSeeOther) + if redirectDir(w, r) { return } |