From 36b8cb828cbfa604cc522ada767a9a057fc87fe2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Mar 2023 09:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Afiles=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E7=AC=A6=E5=8F=B7=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/repo/file.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routers/hat/repo/file.go b/routers/hat/repo/file.go index 0a419b5..31ec59b 100644 --- a/routers/hat/repo/file.go +++ b/routers/hat/repo/file.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" files_service "code.gitea.io/gitea/services/repository/files" hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs" @@ -318,7 +319,8 @@ func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileL name := entry.Name() treePath = name - selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", ctx.Repo.Repository.APIURL(), treePath, ref)) + selfURL, err := url.Parse(ctx.Repo.Repository.APIURL() + "/contents/" + util.PathEscapeSegments(treePath) + "?ref=" + url.QueryEscape(ref)) + if err != nil { return nil, err } @@ -328,7 +330,8 @@ func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileL if refType == "invalid" { return nil, fmt.Errorf("no commit found for the ref [ref: %s]", ref) } - htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", ctx.Repo.Repository.HTMLURL(), refType, ref, treePath)) + // htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", ctx.Repo.Repository.HTMLURL(), refType, ref, treePath)) + htmlURL, err := url.Parse(ctx.Repo.Repository.APIURL() + "/src/" + url.QueryEscape(string(refType)) + "/" + url.QueryEscape(ref) + "/" + util.PathEscapeSegments(treePath)) if err != nil { return nil, err }