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

Fix trimming of leading and trailing spaces when adding a new file #31507

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

charles7668
Copy link
Contributor

close #31478

@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 27, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 27, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Jun 27, 2024
Copy link
Member

@silverwind silverwind left a 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.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 27, 2024
for i, v := range treePath {
treePath[i] = strings.TrimSpace(v)
}
form.TreePath = strings.Join(treePath, "/")
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@charles7668 charles7668 Jun 28, 2024

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.

Copy link
Member

@silverwind silverwind Jun 28, 2024

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.

Copy link
Member

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.

Copy link
Contributor Author

@charles7668 charles7668 Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firefox_XPWa8Ls4eU

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.

@silverwind silverwind self-requested a review June 27, 2024 13:49
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 27, 2024
for i, v := range treePath {
treePath[i] = strings.TrimSpace(v)
}
form.TreePath = strings.Join(treePath, "/")
Copy link
Member

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.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 28, 2024
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code modifies/js size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider sanitizing filenames for whitespaces when creating a file from web interface
5 participants