File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -250,15 +250,17 @@ func Contexter() macaron.Handler {
250
250
if ctx .Query ("go-get" ) == "1" {
251
251
ownerName := c .Params (":username" )
252
252
repoName := c .Params (":reponame" )
253
- if ownerName == "" || repoName == "" {
253
+ trimmedRepoName := strings .TrimSuffix (repoName , ".git" )
254
+
255
+ if ownerName == "" || trimmedRepoName == "" {
254
256
_ , _ = c .Write ([]byte (`<!doctype html>
255
257
<html>
256
258
<body>
257
259
invalid import path
258
260
</body>
259
261
</html>
260
262
` ))
261
- c .WriteHeader (404 )
263
+ c .WriteHeader (400 )
262
264
return
263
265
}
264
266
branchName := "master"
@@ -288,7 +290,7 @@ func Contexter() macaron.Handler {
288
290
</body>
289
291
</html>
290
292
` , map [string ]string {
291
- "GoGetImport" : ComposeGoGetImport (ownerName , strings . TrimSuffix ( repoName , ".git" ) ),
293
+ "GoGetImport" : ComposeGoGetImport (ownerName , trimmedRepoName ),
292
294
"CloneLink" : models .ComposeHTTPSCloneURL (ownerName , repoName ),
293
295
"GoDocDirectory" : prefix + "{/dir}" ,
294
296
"GoDocFile" : prefix + "{/dir}/{file}#L{line}" ,
Original file line number Diff line number Diff line change @@ -201,13 +201,14 @@ func ComposeGoGetImport(owner, repo string) string {
201
201
// .netrc file.
202
202
func EarlyResponseForGoGetMeta (ctx * Context ) {
203
203
username := ctx .Params (":username" )
204
- reponame := ctx .Params (":reponame" )
204
+ reponame := strings . TrimSuffix ( ctx .Params (":reponame" ), ".git " )
205
205
if username == "" || reponame == "" {
206
- ctx .PlainText (404 , []byte ("invalid repository path" ))
206
+ ctx .PlainText (400 , []byte ("invalid repository path" ))
207
+ return
207
208
}
208
209
ctx .PlainText (200 , []byte (com .Expand (`<meta name="go-import" content="{GoGetImport} git {CloneLink}">` ,
209
210
map [string ]string {
210
- "GoGetImport" : ComposeGoGetImport (username , strings . TrimSuffix ( reponame , ".git" ) ),
211
+ "GoGetImport" : ComposeGoGetImport (username , reponame ),
211
212
"CloneLink" : models .ComposeHTTPSCloneURL (username , reponame ),
212
213
})))
213
214
}
You can’t perform that action at this time.
0 commit comments