@@ -163,7 +163,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
163163 branchName = form .NewBranchName
164164 }
165165
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+ }
167171 treeNames , treePaths := getParentTreeFields (form .TreePath )
168172
169173 ctx .Data ["TreePath" ] = form .TreePath
@@ -373,6 +377,13 @@ func DeleteFile(ctx *context.Context) {
373377func DeleteFilePost (ctx * context.Context , form auth.DeleteRepoFileForm ) {
374378 ctx .Data ["PageIsDelete" ] = true
375379 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+
376387 ctx .Data ["TreePath" ] = ctx .Repo .TreePath
377388 canCommit := renderCommitRights (ctx )
378389
@@ -477,7 +488,12 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
477488 branchName = form .NewBranchName
478489 }
479490
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+
481497 treeNames , treePaths := getParentTreeFields (form .TreePath )
482498 if len (treeNames ) == 0 {
483499 // We must at least have one element for user to input.
0 commit comments