@@ -20,6 +20,7 @@ import (
20
20
"code.gitea.io/gitea/modules/setting"
21
21
"code.gitea.io/gitea/modules/templates"
22
22
"code.gitea.io/gitea/modules/uploader"
23
+ "code.gitea.io/gitea/modules/util"
23
24
)
24
25
25
26
const (
@@ -66,9 +67,9 @@ func editFile(ctx *context.Context, isNewFile bool) {
66
67
treePath := cleanUploadFileName (ctx .Repo .TreePath )
67
68
if treePath != ctx .Repo .TreePath {
68
69
if isNewFile {
69
- ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_new" , ctx .Repo .BranchName , treePath ))
70
+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_new" , util . PathEscapeSegments ( ctx .Repo .BranchName ), util . PathEscapeSegments ( treePath ) ))
70
71
} else {
71
- ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_edit" , ctx .Repo .BranchName , treePath ))
72
+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_edit" , util . PathEscapeSegments ( ctx .Repo .BranchName ), util . PathEscapeSegments ( treePath ) ))
72
73
}
73
74
return
74
75
}
@@ -324,7 +325,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
324
325
return
325
326
}
326
327
327
- ctx .Redirect (ctx .Repo .RepoLink + "/src/branch/" + branchName + "/" + strings . NewReplacer ( "%" , "%25" , "#" , "%23" , " " , "%20" , "?" , "%3F" ). Replace (form .TreePath ))
328
+ ctx .Redirect (ctx .Repo .RepoLink + "/src/branch/" + util . PathEscapeSegments ( branchName ) + "/" + util . PathEscapeSegments (form .TreePath ))
328
329
}
329
330
330
331
// EditFilePost response for editing file
@@ -376,7 +377,7 @@ func DeleteFile(ctx *context.Context) {
376
377
treePath := cleanUploadFileName (ctx .Repo .TreePath )
377
378
378
379
if treePath != ctx .Repo .TreePath {
379
- ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_delete" , ctx .Repo .BranchName , treePath ))
380
+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_delete" , util . PathEscapeSegments ( ctx .Repo .BranchName ), util . PathEscapeSegments ( treePath ) ))
380
381
return
381
382
}
382
383
@@ -460,7 +461,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
460
461
}
461
462
462
463
ctx .Flash .Success (ctx .Tr ("repo.editor.file_delete_success" , ctx .Repo .TreePath ))
463
- ctx .Redirect (ctx .Repo .RepoLink + "/src/branch/" + branchName )
464
+ ctx .Redirect (ctx .Repo .RepoLink + "/src/branch/" + util . PathEscapeSegments ( branchName ) )
464
465
}
465
466
466
467
func renderUploadSettings (ctx * context.Context ) {
@@ -477,7 +478,7 @@ func UploadFile(ctx *context.Context) {
477
478
canCommit := renderCommitRights (ctx )
478
479
treePath := cleanUploadFileName (ctx .Repo .TreePath )
479
480
if treePath != ctx .Repo .TreePath {
480
- ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_upload" , ctx .Repo .BranchName , treePath ))
481
+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_upload" , util . PathEscapeSegments ( ctx .Repo .BranchName ), util . PathEscapeSegments ( treePath ) ))
481
482
return
482
483
}
483
484
ctx .Repo .TreePath = treePath
@@ -596,7 +597,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
596
597
return
597
598
}
598
599
599
- ctx .Redirect (ctx .Repo .RepoLink + "/src/branch/" + branchName + "/" + form .TreePath )
600
+ ctx .Redirect (ctx .Repo .RepoLink + "/src/branch/" + util . PathEscapeSegments ( branchName ) + "/" + util . PathEscapeSegments ( form .TreePath ) )
600
601
}
601
602
602
603
func cleanUploadFileName (name string ) string {
0 commit comments