-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
escape filename when assemble URL #22850
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
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))) | ||||||
|
||||||
| downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, util.PathEscapeSegments(treePath))) | |
| downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), url.PathEscape(refType), util.PathEscapeSegments(ref), util.PathEscapeSegments(treePath))) |
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.
Does it work if ref contains / ? eg: ref="a/b", treePath="c/d", then there will be "/a/b/c/d", which is the ref part. Or, if actually the endpoint doesn't care about it, then there would be no problem.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yup, that's getRefNameFromPath. By design if ref /a exists, there should be no ref /a/b, so it's safe.
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.
I think the ref name should always be URL safe but... It's really much better to just escape the thing
Outdated
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.
| htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, util.PathEscapeSegments(treePath))) | |
| htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), url.PathEscape(refType), util.PathEscapeSegments(ref), util.PathEscapeSegments(treePath))) |
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()