Consider sanitizing filenames for whitespaces when creating a file from web interface #13200

Closed
opened 2025-11-02 10:34:42 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @diamante0018 on GitHub (Jun 24, 2024).

Description

When creating a filename using the website you may accidentally add whitespace to the filename which can lead to unexpected events, attempting to clone a repo which contains a file that has a trailing whitespace on Windows leads to this error:

git clone https://demo.gitea.com/future/test-filename.git
Cloning into 'test-filename'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
error: invalid path 'there-is-a-whitespace '
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'

This leads me to open this discussion to see if it's worth asking the gitea devs to perform whitespace removal (trim) at both the end and start of the filename string so this can be prevented automatically.

Gitea Version

1.23.0+dev-273-ga4899ffa24

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

test2
test1

Git Version

demo.gitea.com

Operating System

demo.gitea.com

How are you running Gitea?

demo.gitea.com

Database

None

Originally created by @diamante0018 on GitHub (Jun 24, 2024). ### Description When creating a filename using the website you may accidentally add whitespace to the filename which can lead to unexpected events, attempting to clone a repo which contains a file that has a trailing whitespace on Windows leads to this error: ``` git clone https://demo.gitea.com/future/test-filename.git Cloning into 'test-filename'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done. error: invalid path 'there-is-a-whitespace ' fatal: unable to checkout working tree warning: Clone succeeded, but checkout failed. You can inspect what was checked out with 'git status' and retry with 'git restore --source=HEAD :/' ``` This leads me to open this discussion to see if it's worth asking the gitea devs to perform whitespace removal (trim) at both the end and start of the filename string so this can be prevented automatically. ### Gitea Version 1.23.0+dev-273-ga4899ffa24 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots ![test2](https://github.com/go-gitea/gitea/assets/37080671/bff0f66d-82ff-4e34-b659-95791e192d5c) ![test1](https://github.com/go-gitea/gitea/assets/37080671/fe5fe532-bff1-4a3d-84db-59cb6f784618) ### Git Version demo.gitea.com ### Operating System demo.gitea.com ### How are you running Gitea? demo.gitea.com ### Database None
GiteaMirror added the type/bug label 2025-11-02 10:34:42 -06:00
Author
Owner

@yp05327 commented on GitHub (Jun 27, 2024):

Maybe we need a IsVaildFileName in backend, as it is not checked now and already caused some problems like #29907

@yp05327 commented on GitHub (Jun 27, 2024): Maybe we need a `IsVaildFileName` in backend, as it is not checked now and already caused some problems like #29907
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13200