From 0ef4deb35d59aa0df54dfbc886503ec2c14bfadd Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 11 Feb 2025 12:43:36 +0800 Subject: [PATCH] repo_{raw,tree}: Redirect if visiting file but path_spec ends with slash --- handle_repo_raw.go | 4 ++++ handle_repo_tree.go | 4 ++++ diff --git a/handle_repo_raw.go b/handle_repo_raw.go index 534ed4df600c33ab71a5027ac9e6e4b5b76857a5..811fea8e0aa6b67aa772e3efaa48260d13c362d1 100644 --- a/handle_repo_raw.go +++ b/handle_repo_raw.go @@ -48,6 +48,10 @@ if err != nil { _, _ = w.Write([]byte("Error retrieving path: " + err.Error())) return } + if len(raw_path_spec) != 0 && raw_path_spec[len(raw_path_spec)-1] == '/' { + http.Redirect(w, r, "../" + path_spec, http.StatusSeeOther) + return + } file_contents, err := file.Contents() if err != nil { _, _ = w.Write([]byte("Error reading file: " + err.Error())) diff --git a/handle_repo_tree.go b/handle_repo_tree.go index 7a996921b3cc50dfba7f21014cacec522b86291b..1ef71791a812aa38f2a74044aff17acad6e6dd0c 100644 --- a/handle_repo_tree.go +++ b/handle_repo_tree.go @@ -53,6 +53,10 @@ if err != nil { _, _ = w.Write([]byte("Error retrieving path: " + err.Error())) return } + if len(raw_path_spec) != 0 && raw_path_spec[len(raw_path_spec)-1] == '/' { + http.Redirect(w, r, "../" + path_spec, http.StatusSeeOther) + return + } file_contents, err := file.Contents() if err != nil { _, _ = w.Write([]byte("Error reading file: " + err.Error())) -- 2.48.1