From 84a1c0cec0cf08977183264c7319a318ad092f2a Mon Sep 17 00:00:00 2001 From: NewName Date: Wed, 25 Dec 2024 06:28:27 +0800 Subject: [PATCH] Update main.go --- ghproxy/main.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/ghproxy/main.go b/ghproxy/main.go index b84cafc..a0e5256 100644 --- a/ghproxy/main.go +++ b/ghproxy/main.go @@ -207,10 +207,27 @@ func checkURL(u string) []string { // 匹配用户名、仓库名,或者用户名/仓库名 func checkList(matches, list []string) bool { - for _, item := range list { - if strings.HasPrefix(matches[0], item) || strings.HasPrefix(matches[1], item) || strings.HasPrefix(matches[0]+"/"+matches[1], item) { - return true - } - } - return false + if len(matches) == 0 { + return false + } + + for _, item := range list { + // 检查第一个匹配 + if strings.HasPrefix(matches[0], item) { + return true + } + // 只有当存在第二个匹配时才检查 + if len(matches) > 1 { + if strings.HasPrefix(matches[1], item) { + return true + } + // 只有当存在两个捕获组时才检查组合 + if len(matches) > 2 { + if strings.HasPrefix(matches[0]+"/"+matches[1], item) { + return true + } + } + } + } + return false }