@@ -62,6 +62,16 @@ func editFile(ctx *context.Context, isNewFile bool) {
6262 ctx .Data ["RequireSimpleMDE" ] = true
6363 canCommit := renderCommitRights (ctx )
6464
65+ treePath := cleanUploadFileName (ctx .Repo .TreePath )
66+ if treePath != ctx .Repo .TreePath {
67+ if isNewFile {
68+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_new" , ctx .Repo .BranchName , treePath ))
69+ } else {
70+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_edit" , ctx .Repo .BranchName , treePath ))
71+ }
72+ return
73+ }
74+
6575 treeNames , treePaths := getParentTreeFields (ctx .Repo .TreePath )
6676
6777 if ! isNewFile {
@@ -155,7 +165,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
155165
156166 oldBranchName := ctx .Repo .BranchName
157167 branchName := oldBranchName
158- oldTreePath := ctx .Repo .TreePath
168+ oldTreePath := cleanUploadFileName ( ctx .Repo .TreePath )
159169 lastCommit := form .LastCommit
160170 form .LastCommit = ctx .Repo .Commit .ID .String ()
161171
@@ -328,7 +338,11 @@ func NewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
328338
329339// DiffPreviewPost render preview diff page
330340func DiffPreviewPost (ctx * context.Context , form auth.EditPreviewDiffForm ) {
331- treePath := ctx .Repo .TreePath
341+ treePath := cleanUploadFileName (ctx .Repo .TreePath )
342+ if len (treePath ) == 0 {
343+ ctx .Error (500 , "file name to diff is invalid" )
344+ return
345+ }
332346
333347 entry , err := ctx .Repo .Commit .GetTreeEntryByPath (treePath )
334348 if err != nil {
@@ -358,7 +372,14 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
358372func DeleteFile (ctx * context.Context ) {
359373 ctx .Data ["PageIsDelete" ] = true
360374 ctx .Data ["BranchLink" ] = ctx .Repo .RepoLink + "/src/" + ctx .Repo .BranchNameSubURL ()
361- ctx .Data ["TreePath" ] = ctx .Repo .TreePath
375+ treePath := cleanUploadFileName (ctx .Repo .TreePath )
376+
377+ if treePath != ctx .Repo .TreePath {
378+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_delete" , ctx .Repo .BranchName , treePath ))
379+ return
380+ }
381+
382+ ctx .Data ["TreePath" ] = treePath
362383 canCommit := renderCommitRights (ctx )
363384
364385 ctx .Data ["commit_summary" ] = ""
@@ -453,6 +474,12 @@ func UploadFile(ctx *context.Context) {
453474 ctx .Data ["PageIsUpload" ] = true
454475 renderUploadSettings (ctx )
455476 canCommit := renderCommitRights (ctx )
477+ treePath := cleanUploadFileName (ctx .Repo .TreePath )
478+ if treePath != ctx .Repo .TreePath {
479+ ctx .Redirect (path .Join (ctx .Repo .RepoLink , "_upload" , ctx .Repo .BranchName , treePath ))
480+ return
481+ }
482+ ctx .Repo .TreePath = treePath
456483
457484 treeNames , treePaths := getParentTreeFields (ctx .Repo .TreePath )
458485 if len (treeNames ) == 0 {
0 commit comments