修复:files特殊符号无法正常加载

This commit is contained in:
yystopf 2023-03-29 09:55:57 +08:00
parent e1d71eeea2
commit 36b8cb828c
1 changed files with 5 additions and 2 deletions

View File

@ -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
}