fix: create file branch name use escape

This commit is contained in:
yystopf 2021-12-27 17:34:24 +08:00
parent c617532f47
commit c13048756b
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