-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
escape filename when assemble URL #22850
Changes from 2 commits
92a7602
1b766ad
ec07809
5734c4c
b03c2b9
0cc708d
f035728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |||||
"code.gitea.io/gitea/modules/git" | ||||||
"code.gitea.io/gitea/modules/setting" | ||||||
api "code.gitea.io/gitea/modules/structs" | ||||||
"code.gitea.io/gitea/modules/util" | ||||||
) | ||||||
|
||||||
// ContentType repo content type | ||||||
|
@@ -158,7 +159,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref | |||||
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(), util.PathEscapeSegments(treePath), origRef)) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
@@ -217,15 +218,15 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref | |||||
} | ||||||
// Handle links | ||||||
if entry.IsRegular() || entry.IsLink() { | ||||||
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, util.PathEscapeSegments(treePath))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ref should be escape path segments. The code does the magic of handling the ref There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yup, that's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the ref name should always be URL safe but... It's really much better to just escape the thing |
||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
downloadURLString := downloadURL.String() | ||||||
contentsResponse.DownloadURL = &downloadURLString | ||||||
} | ||||||
if !entry.IsSubModule() { | ||||||
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, util.PathEscapeSegments(treePath))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
origRef needs to be url.QueryEscape()