@@ -163,7 +163,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
163
163
branchName = form .NewBranchName
164
164
}
165
165
166
- form .TreePath = strings .Trim (path .Clean ("/" + form .TreePath ), " /" )
166
+ form .TreePath = cleanUploadFileName (form .TreePath )
167
+ if len (form .TreePath ) == 0 {
168
+ ctx .Error (500 , "Upload file name is invalid" )
169
+ return
170
+ }
167
171
treeNames , treePaths := getParentTreeFields (form .TreePath )
168
172
169
173
ctx .Data ["TreePath" ] = form .TreePath
@@ -373,6 +377,13 @@ func DeleteFile(ctx *context.Context) {
373
377
func DeleteFilePost (ctx * context.Context , form auth.DeleteRepoFileForm ) {
374
378
ctx .Data ["PageIsDelete" ] = true
375
379
ctx .Data ["BranchLink" ] = ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ()
380
+
381
+ ctx .Repo .TreePath = cleanUploadFileName (ctx .Repo .TreePath )
382
+ if len (ctx .Repo .TreePath ) == 0 {
383
+ ctx .Error (500 , "Delete file name is invalid" )
384
+ return
385
+ }
386
+
376
387
ctx .Data ["TreePath" ] = ctx .Repo .TreePath
377
388
canCommit := renderCommitRights (ctx )
378
389
@@ -477,7 +488,12 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
477
488
branchName = form .NewBranchName
478
489
}
479
490
480
- form .TreePath = strings .Trim (path .Clean ("/" + form .TreePath ), " /" )
491
+ form .TreePath = cleanUploadFileName (form .TreePath )
492
+ if len (form .TreePath ) == 0 {
493
+ ctx .Error (500 , "Upload file name is invalid" )
494
+ return
495
+ }
496
+
481
497
treeNames , treePaths := getParentTreeFields (form .TreePath )
482
498
if len (treeNames ) == 0 {
483
499
// We must at least have one element for user to input.
0 commit comments