修复文件名前缀带空格不能编辑和删除问题

This commit is contained in:
wonderful 2022-04-12 14:11:43 +08:00
commit d59fbd0053
2 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,10 @@
/*
* @Descripttion:
* @Author: hang
* @version:
* @Date: 2021-10-28 18:21:53
* @LastEditors: hang
*/
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.package repofiles
@ -12,7 +19,7 @@ import (
// CleanUploadFileName Trims a filename and returns empty string if it is a .git directory
func CleanUploadFileName(name string) string {
// Rebase the filename
name = strings.Trim(path.Clean("/"+name), " /")
name = strings.Trim(path.Clean("/"+name), "/")
// Git disallows any filenames to have a .git directory in them.
for _, part := range strings.Split(name, "/") {
if strings.ToLower(part) == ".git" {

View File

@ -727,7 +727,7 @@ func UploadFilePost(ctx *context.Context) {
func cleanUploadFileName(name string) string {
// Rebase the filename
name = strings.Trim(path.Clean("/"+name), " /")
name = strings.Trim(path.Clean("/"+name), "/")
// Git disallows any filenames to have a .git directory in them.
for _, part := range strings.Split(name, "/") {
if strings.ToLower(part) == ".git" {