From 8d7619c7e430c389ec1d1c4041d60b12b1529a82 Mon Sep 17 00:00:00 2001 From: starry <115192496+sky22333@users.noreply.github.com> Date: Fri, 28 Nov 2025 13:37:23 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E6=B7=BB=E5=8A=A0=E5=8A=A0=E9=80=9F=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/proxy_shell.go | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/utils/proxy_shell.go b/src/utils/proxy_shell.go index 12af000..b7bd1d6 100644 --- a/src/utils/proxy_shell.go +++ b/src/utils/proxy_shell.go @@ -10,7 +10,7 @@ import ( ) // GitHub URL正则表达式 -var githubRegex = regexp.MustCompile(`https?://(?:github\.com|raw\.githubusercontent\.com|raw\.github\.com|gist\.githubusercontent\.com|gist\.github\.com|api\.github\.com)[^\s'"]+`) +var githubRegex = regexp.MustCompile(`(?:^|[\s'"(=,\[{;|&<>])https?://(?:github\.com|raw\.githubusercontent\.com|raw\.github\.com|gist\.githubusercontent\.com|gist\.github\.com|api\.github\.com)[^\s'")]*`) // ProcessSmart Shell脚本智能处理函数 func ProcessSmart(input io.ReadCloser, isCompressed bool, host string) (io.Reader, int64, error) { @@ -70,28 +70,34 @@ func readShellContent(input io.ReadCloser, isCompressed bool) (string, error) { } func processGitHubURLs(content, host string) string { - return githubRegex.ReplaceAllStringFunc(content, func(url string) string { - return transformURL(url, host) + return githubRegex.ReplaceAllStringFunc(content, func(match string) string { + // 如果匹配包含前缀分隔符,保留它,防止出现重复转换 + if len(match) > 0 && match[0] != 'h' { + prefix := match[0:1] + url := match[1:] + return prefix + transformURL(url, host) + } + return transformURL(match, host) }) } // transformURL URL转换函数 func transformURL(url, host string) string { - if strings.Contains(url, host) { - return url - } + if strings.Contains(url, host) { + return url + } - if strings.HasPrefix(url, "http://") { - url = "https" + url[4:] - } else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "//") { - url = "https://" + url - } + if strings.HasPrefix(url, "http://") { + url = "https" + url[4:] + } else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "//") { + url = "https://" + url + } - // 确保 host 有协议头 - if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") { - host = "https://" + host - } - host = strings.TrimSuffix(host, "/") + // 确保 host 有协议头 + if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") { + host = "https://" + host + } + host = strings.TrimSuffix(host, "/") - return host + "/" + url -} + return host + "/" + url +} \ No newline at end of file