-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix Go 1.13 private repository go get issue #8100
Fix Go 1.13 private repository go get issue #8100
Conversation
Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
@@ -249,6 +249,17 @@ func Contexter() macaron.Handler { | |||
if ctx.Query("go-get") == "1" { | |||
ownerName := c.Params(":username") | |||
repoName := c.Params(":reponame") | |||
if ownerName == "" || repoName == "" { | |||
_, _ = c.Write([]byte(`<!doctype html> |
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.
if returned error, you should give a 500 I think.
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.
Why not see the problem the other way and simply ignore go-get params instead of erroring ?
if ctx.Query("go-get") == "1" && ownerName != "" && repoName != "" {
}
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.
This could be break down in two if
obviously.
if ctx.Query("go-get") == "1"
ownerName := c.Params(":username")
repoName := c.Params(":reponame")
if ownerName != "" && repoName != "" {
... Do go-get work
}
}
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.
But else we still need return 404 but not continue the other work.
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.
Once ctx.Query("go-get") == "1"
, it should return anyway here.
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 a 400 should be returned because in this case the client has not provided adequate information for the server to provide an import URL from the its request.
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.
Line 58 in 85202d4
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git") |
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.
Or perhaps in trimmedRepoName
, such that this is not interfered with:
gitea/modules/context/context.go
Line 258 in bb609ca
prefix := setting.AppURL + path.Join(url.PathEscape(ownerName), url.PathEscape(repoName), "src", "branch", util.PathEscapeSegments(branchName)) |
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.
Why we should return an error ? For exemple github doesn't trigger an error on an profile if you use go-get param. Futhermore triggering an error from a supervision point could be misleading. I will not block as it need a quick fix.
modules/context/repo.go
Outdated
@@ -202,6 +202,9 @@ func ComposeGoGetImport(owner, repo string) string { | |||
func EarlyResponseForGoGetMeta(ctx *Context) { | |||
username := ctx.Params(":username") | |||
reponame := ctx.Params(":reponame") | |||
if username == "" || reponame == "" { | |||
ctx.PlainText(404, []byte("invalid repository path")) |
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.
return
@@ -202,6 +202,9 @@ func ComposeGoGetImport(owner, repo string) string { | |||
func EarlyResponseForGoGetMeta(ctx *Context) { |
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.
Same here we can check previously to calling this method and maybe pass username
and reponame
as args since they are already extracted and cleaned from context before calling:
Line 58 in 85202d4
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git") |
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.
Would it not be preferable to add this for username
as well in case only .git
is appended to the Gitea instance URL?
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 guess not because it seems possible to have the suffix .git
in a username or organization name.
Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
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.
This should be sent to master branch first. I'm going to mark this as blocked so we don't merge this prematurely.
@rutgerbrf please send a PR to master also. |
Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
* Fix Go 1.13 invalid import path creation Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl> * Apply suggested changes from #8100 Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
Since #8112 merged, I have removed the blocked label. @techknowlogick |
@techknowlogick it is been merged to master please approve |
Fixes #8095.