Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not edit/delete a file when its name starts with spaces #18176

Closed
wxiaoguang opened this issue Jan 4, 2022 · 1 comment · Fixed by #18334
Closed

Can not edit/delete a file when its name starts with spaces #18176

wxiaoguang opened this issue Jan 4, 2022 · 1 comment · Fixed by #18334
Labels

Comments

@wxiaoguang
Copy link
Contributor

  1. There are two cleanUploadFileName functions
  2. The spaces in filenames are trimmed
  3. If a file name starts with space eg: decode(%20a.txt), then it can not be edited/deleted from the web UI

@zeripath do you have any idea about why the spaces are trimmed? this change was introduced by #5702

func cleanUploadFileName(name string) string {
// Rebase the filename
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" {
return ""
}
}
return name
}

// 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), " /")
// Git disallows any filenames to have a .git directory in them.
for _, part := range strings.Split(name, "/") {
if strings.ToLower(part) == ".git" {
return ""
}
}
return name
}

image

@zeripath
Copy link
Contributor

I think the trim can safely be dropped

zeripath added a commit to zeripath/gitea that referenced this issue Jan 19, 2022
In go-gitea#5702 it was decided to trim preceding and suffixed spaces aswell as / from
editing file filenames. This was because at this point in time the url-safety of
gitea was much poorer.

We can now drop this requirement and file editing should work correctly.

Fix go-gitea#18176

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Jan 19, 2022
…18334)

* Stop trimming preceding and suffixing spaces from editor filenames

In #5702 it was decided to trim preceding and suffixed spaces aswell as / from
editing file filenames. This was because at this point in time the url-safety of
Gitea was much poorer.

We can now drop this requirement and file editing should work correctly.

Fix #18176

Signed-off-by: Andrew Thornton <art27@cantab.net>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…o-gitea#18334)

* Stop trimming preceding and suffixing spaces from editor filenames

In go-gitea#5702 it was decided to trim preceding and suffixed spaces aswell as / from
editing file filenames. This was because at this point in time the url-safety of
Gitea was much poorer.

We can now drop this requirement and file editing should work correctly.

Fix go-gitea#18176

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants