@@ -62,6 +62,16 @@ func editFile(ctx *context.Context, isNewFile bool) {
62
62
ctx .Data ["RequireSimpleMDE" ] = true
63
63
canCommit := renderCommitRights (ctx )
64
64
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
+
65
75
treeNames , treePaths := getParentTreeFields (ctx .Repo .TreePath )
66
76
67
77
if ! isNewFile {
@@ -155,7 +165,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
155
165
156
166
oldBranchName := ctx .Repo .BranchName
157
167
branchName := oldBranchName
158
- oldTreePath := ctx .Repo .TreePath
168
+ oldTreePath := cleanUploadFileName ( ctx .Repo .TreePath )
159
169
lastCommit := form .LastCommit
160
170
form .LastCommit = ctx .Repo .Commit .ID .String ()
161
171
@@ -328,7 +338,11 @@ func NewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
328
338
329
339
// DiffPreviewPost render preview diff page
330
340
func 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
+ }
332
346
333
347
entry , err := ctx .Repo .Commit .GetTreeEntryByPath (treePath )
334
348
if err != nil {
@@ -358,7 +372,14 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
358
372
func DeleteFile (ctx * context.Context ) {
359
373
ctx .Data ["PageIsDelete" ] = true
360
374
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
362
383
canCommit := renderCommitRights (ctx )
363
384
364
385
ctx .Data ["commit_summary" ] = ""
@@ -453,6 +474,12 @@ func UploadFile(ctx *context.Context) {
453
474
ctx .Data ["PageIsUpload" ] = true
454
475
renderUploadSettings (ctx )
455
476
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
456
483
457
484
treeNames , treePaths := getParentTreeFields (ctx .Repo .TreePath )
458
485
if len (treeNames ) == 0 {
0 commit comments