Merge pull request '创建文件分支名称使用urlencode' (#39) from yystopf/gitea-1156:develop into develop

This commit is contained in:
yystopf 2021-12-27 17:39:25 +08:00
commit 6c4cc40f80
1 changed files with 3 additions and 2 deletions

View File

@ -103,7 +103,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
if ref == "" {
ref = repo.DefaultBranch
}
origRef := ref
origRef := fmt.Sprintf("%s", url.PathEscape(ref))
// Check that the path given in opts.treePath is valid (not a git path)
cleanTreePath := CleanUploadFileName(treePath)
@ -188,7 +188,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
}
// Handle links
if entry.IsRegular() || entry.IsLink() {
ref = fmt.Sprintf("%s", strings.Replace(ref, "%", "%25", -1))
ref = fmt.Sprintf("%s", url.PathEscape(ref))
downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath))
if err != nil {
return nil, err
@ -197,6 +197,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
contentsResponse.DownloadURL = &downloadURLString
}
if !entry.IsSubModule() {
ref = fmt.Sprintf("%s", url.PathEscape(ref))
htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath))
if err != nil {
return nil, err