From 623d0c1a16df8ef40d2f738150f28b23d72cc5bf Mon Sep 17 00:00:00 2001
From: Runxi Yu <me@runxiyu.org>
Date: Wed, 12 Feb 2025 11:18:03 +0800
Subject: router: Stricter URL

---
 router.go | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/router.go b/router.go
index ed0e9b5..bfbba66 100644
--- a/router.go
+++ b/router.go
@@ -85,9 +85,21 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 				params["rest"] = strings.Join(segments[separator_index+4:], "/")
 				handle_repo_raw(w, r, params)
 			case "log":
+				if non_empty_last_segments_len != separator_index+5 {
+					fmt.Fprintln(w, "Too many parameters")
+					return
+				}
+				if dir_mode {
+					http.Redirect(w, r, strings.TrimSuffix(r.URL.Path, "/"), http.StatusSeeOther)
+					return
+				}
 				params["ref"] = segments[separator_index+4]
 				handle_repo_log(w, r, params)
 			case "commit":
+				if dir_mode {
+					http.Redirect(w, r, strings.TrimSuffix(r.URL.Path, "/"), http.StatusSeeOther)
+					return
+				}
 				params["commit_id"] = segments[separator_index+4]
 				handle_repo_commit(w, r, params)
 			}
-- 
cgit v1.2.3