Modify the file name with spaces and cannot be deleted

This commit is contained in:
hang 2022-04-12 14:07:09 +08:00
parent 60b3497005
commit dbb0de14cc
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" {