diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 4ff86b5a66..f8e291a4d1 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -392,6 +392,14 @@ func EditFilePost(ctx *context.Context) { // NewFilePost response for creating file func NewFilePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.EditRepoFileForm) + + // trim leading and trailing spaces from the tree path + treePath := strings.Split(form.TreePath, "/") + for i, v := range treePath { + treePath[i] = strings.TrimSpace(v) + } + form.TreePath = strings.Join(treePath, "/") + editFilePost(ctx, *form, true) }