forked from Gitlink/gitea-1156
fix: url must query encode
This commit is contained in:
parent
2e1e54f254
commit
059487b243
modules/repofiles
|
@ -103,18 +103,20 @@ func GetContentsOrList(ctx context.Context, repo *models.Repository, treePath, r
|
|||
subTreePath := path.Join(treePath, name)
|
||||
fileContentResponse, err := GetContents(repo, subTreePath, origRef, true)
|
||||
for _, commitInfo := range commitsInfo {
|
||||
if commitInfo.Entry.Name() == fileContentResponse.Name {
|
||||
var entryCommit *git.Commit
|
||||
entryCommit = commitInfo.Commit
|
||||
if e.IsSubModule() {
|
||||
entryCommit = commitInfo.SubModuleFile.Commit
|
||||
if commitInfo.Entry != nil && fileContentResponse != nil {
|
||||
if commitInfo.Entry.Name() == fileContentResponse.Name {
|
||||
var entryCommit *git.Commit
|
||||
entryCommit = commitInfo.Commit
|
||||
if e.IsSubModule() {
|
||||
entryCommit = commitInfo.SubModuleFile.Commit
|
||||
}
|
||||
fileContentResponse.LatestCommit = api.ContentsResponseCommit{
|
||||
Message: entryCommit.CommitMessage,
|
||||
LatestCommitSha: entryCommit.ID.String(),
|
||||
Created: entryCommit.Author.When.Unix(),
|
||||
}
|
||||
break
|
||||
}
|
||||
fileContentResponse.LatestCommit = api.ContentsResponseCommit{
|
||||
Message: entryCommit.CommitMessage,
|
||||
LatestCommitSha: entryCommit.ID.String(),
|
||||
Created: entryCommit.Author.When.Unix(),
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -167,8 +169,8 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
|
|||
if refType == "invalid" {
|
||||
return nil, fmt.Errorf("no commit found for the ref [ref: %s]", ref)
|
||||
}
|
||||
|
||||
selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", repo.APIURL(), treePath, origRef))
|
||||
// selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", repo.APIURL(), treePath, origRef))
|
||||
selfURL, err := url.Parse(url.QueryEscape(fmt.Sprintf("%s/contents/%s?ref=%s", repo.APIURL(), treePath, origRef)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -219,7 +221,8 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
|
|||
// Handle links
|
||||
if entry.IsRegular() || entry.IsLink() {
|
||||
ref = fmt.Sprintf("%s", url.PathEscape(ref))
|
||||
downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath))
|
||||
// downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath))
|
||||
downloadURL, err := url.Parse(url.QueryEscape(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -228,15 +231,16 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
|
|||
}
|
||||
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))
|
||||
// htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath))
|
||||
htmlURL, err := url.Parse(url.QueryEscape(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
htmlURLString := htmlURL.String()
|
||||
contentsResponse.HTMLURL = &htmlURLString
|
||||
contentsResponse.Links.HTMLURL = &htmlURLString
|
||||
|
||||
gitURL, err := url.Parse(fmt.Sprintf("%s/git/blobs/%s", repo.APIURL(), entry.ID.String()))
|
||||
// gitURL, err := url.Parse(fmt.Sprintf("%s/git/blobs/%s", repo.APIURL(), entry.ID.String()))
|
||||
gitURL, err := url.Parse(url.QueryEscape(fmt.Sprintf("%s/git/blobs/%s", repo.APIURL(), entry.ID.String())))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue