-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Notify the user when the file path contains leading or trailing spaces and fix the error message for invalid file names. #31507
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok. Personally I would have tried to do it in frontend, but this is also fine and probably simpler than frontend stuff.
routers/web/repo/editor.go
Outdated
for i, v := range treePath { | ||
treePath[i] = strings.TrimSpace(v) | ||
} | ||
form.TreePath = strings.Join(treePath, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the path could be something like / / / /
, just press Space Slash Space Slash on the editor page 🤣
Then the tree path becomes "////", which doesn't seem good.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the tree path becomes "////", which doesn't seem good.
I assume the backend would reject that? Seems like right behaviour to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more edge cases: for example, what happens to foo/ .. /bar
? Will it be rejected or become foo/../bar
then become bar
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub has another good behavior: if ../
is inputted, then it changes the path to parent, not sure whether it is implemented in Gitea's UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with GitHub, I think GitHub also uses my suggestion: do not do too much for end users, only warn them.
On GitHub, it shows a warning but does not take any action for users. This is my test: 't2 / t3 / t4 /test'
This problem is the same as #31478.
I'm not sure if we need to follow this behavior or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that GitHub has this warning, then I agree, we should implement it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both approaches sound good to me.
Both get an LGTM from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some warnings for users similar to GitHub.
However, I have kept backend processing for spaces.
On GitHub, it only removes spaces from filenames, not from parent directories. Since Gitea can run on different operating systems, leading or trailing spaces may cause some problems. Therefore, I have retained space processing.
routers/web/repo/editor.go
Outdated
for i, v := range treePath { | ||
treePath[i] = strings.TrimSpace(v) | ||
} | ||
form.TreePath = strings.Join(treePath, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both approaches sound good to me.
Both get an LGTM from me.
0c3e581
to
2543f15
Compare
@silverwind could you review again? |
|
Paste |
# Conflicts: # web_src/js/features/repo-editor.ts
* giteaofficial/main: Notify the user when the file path contains leading or trailing spaces and fix the error message for invalid file names. (go-gitea#31507) Fix wrong status of `Set up Job` when first step is skipped (go-gitea#32120) Fix bug when deleting a migrated branch (go-gitea#32075) Include collaboration repositories on dashboard source/forks/mirrors list (go-gitea#31946) Display head branch more comfortable on pull request view (go-gitea#32000) Truncate commit message during Discord webhook push events (go-gitea#31970) Fix template bug of pull request view (go-gitea#32072)
I was unable to create a backport for 1.22. @charles7668, please send one manually. 🍵
|
I think this can be kept v1.23 only. |
close #31478