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

Add trim to FileInfo (issue #70524) #112964

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ichbinsteffen
Copy link

While debugging strange behavior I came across this issue today and had a few head scratching moments until I found that a
new FileInfo(path).Name returns a file name with a trailing space. I did not expect this behavior.

In a full file path, I think there is no risk in trimming it.
Of course it's a different story for directory paths.

I found this Issue (#70524) which I think fully captures this behavior and the discussion validates that it's a problem that deserves a fix.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 26, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

@stephentoub
Copy link
Member

stephentoub commented Feb 26, 2025

In a full file path, I think there is no risk in trimming it.

Spaces are valid characters in file names. The files "something.txt " and "something.txt" are not the same on all platforms.

@stephentoub stephentoub added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Feb 26, 2025
@ichbinsteffen
Copy link
Author

ichbinsteffen commented Feb 26, 2025

@stephentoub

Spaces are valid characters in file names. The files "something.txt " and "something.txt" are not the same on all platforms.

Ah, okay it's just that windows trims filenames. So unix systems always keep them, I didn't think of that.
Would platform specific behavior make sense?

@ichbinsteffen
Copy link
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO community-contribution Indicates that the PR has been added by a community member NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants