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
FullPathResolver: Avoid exception for illegal characters #8575
FullPathResolver: Avoid exception for illegal characters #8575
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8575 +/- ##
==========================================
- Coverage 55.13% 55.12% -0.01%
==========================================
Files 904 904
Lines 65466 65474 +8
Branches 11853 11857 +4
==========================================
- Hits 36094 36093 -1
- Misses 26548 26554 +6
- Partials 2824 2827 +3
Flags with carried forward coverage won't be shown. Click here to find out more. |
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.
LGTM, though once we move to .NET most of this will be irrelevant. In .NET Core 2.1 System.IO has gone an extensive update, and a number of exceptions that were previously thrown aren't thrown any more.
Here's a blog post https://docs.microsoft.com/en-us/archive/blogs/jeremykuhne/system-io-in-net-core-2-1-sneak-peek
4ab6c04
to
23c4b7b
Compare
Many of the changes in the second commit are still needed with Core 2.1. I added one new commit, to be able to show the file in diff tab. RevTree does not work still, will be handled by the .NET Core 2.1 changes (some Path methods that throws when getting extensions etc. Should this be fixed here?) |
23c4b7b
to
21223dc
Compare
Some corrections and more situations handled. It is now possible to view commits with illegal characters in the path, also in the revtree. There has been a number of similar cases in the past, this should prevent some to occur.
Note that the official API is still not updated, the blog post is the best source I found to describe the change. |
Aye! I had to ask questions internally to find this blog. |
Merge at will |
bafe177
to
b32c4a7
Compare
Please fix the history and merge |
b32c4a7
to
cc48144
Compare
I have been a little busy and want ted to revise this again. Some logic cleanups, and a resolve-stage revert |
Just merge it. I think it has been open long enough for protests to surface
:)
|
Avoid exceptions where issues are handled
Avoid throwing when handling Git items, that allows other characters than Windows file systems. Similar to the .NET Core 2.1 API
cc48144
to
60379e3
Compare
Fixes #8571
Fixes #8364
Fixes #8437
Fixes #7862
Proposed changes
FullPathResolver throws if a file name contains Windows illegal characters that could be OK in Git repos.
As FullPathResolver is often used to check if a local file exists for instance to enable menu items, an exception
is normally not required and null can be returned instead.
For instance
File.Exists(null) ==false
.In some situations returning null will still cause a null exceptions instead.
Reviewed the usage of Resolve() to change situations where null should not be fatal. This review is best effort, there may be other situations that should be changed too. Most "null unhandled" are used in Process(), there are other PRs there.
Some handling already use try-catch, like Delete in FormCommit.
An alternative would be to add a new method like
bool TryResolve(string path)
orbool Resolve(string path, bool throw = true)
and change the about 45 of 60 Resolve() call sites to explicitly not throw.Test methodology
Tests updated
✒️ I contribute this code under The Developer Certificate of Origin.