aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context/context.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-09-06 21:44:59 +0800
committerGitHub <noreply@github.com>2019-09-06 21:44:59 +0800
commit88e1c29df192df411c3d1721d32e311daaab4f09 (patch)
tree56462b86a0fc01f839f2abd4656a324cfe790158 /modules/context/context.go
parentc03d75fbd51174d0e7ffdbaf9e9e253438d06cf7 (diff)
downloadgitea-88e1c29df192df411c3d1721d32e311daaab4f09.tar.gz
gitea-88e1c29df192df411c3d1721d32e311daaab4f09.zip
Fix Go 1.13 private repository go get issue (#8112)
* 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>
Diffstat (limited to 'modules/context/context.go')
-rw-r--r--modules/context/context.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/modules/context/context.go b/modules/context/context.go
index e89b2e25c4..ef6c19ed12 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -250,6 +250,19 @@ func Contexter() macaron.Handler {
if ctx.Query("go-get") == "1" {
ownerName := c.Params(":username")
repoName := c.Params(":reponame")
+ trimmedRepoName := strings.TrimSuffix(repoName, ".git")
+
+ if ownerName == "" || trimmedRepoName == "" {
+ _, _ = c.Write([]byte(`<!doctype html>
+<html>
+ <body>
+ invalid import path
+ </body>
+</html>
+`))
+ c.WriteHeader(400)
+ return
+ }
branchName := "master"
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
@@ -277,7 +290,7 @@ func Contexter() macaron.Handler {
</body>
</html>
`, map[string]string{
- "GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")),
+ "GoGetImport": ComposeGoGetImport(ownerName, trimmedRepoName),
"CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName),
"GoDocDirectory": prefix + "{/dir}",
"GoDocFile": prefix + "{/dir}/{file}#L{line}",