Improve path/uri handling (#82)

* Improve file path special characters handling

* More specific tests

* Optimize EnhancedStackTrace.TryGetFullPath to prevent exceptions being thrown and the immediately re-caught
This commit is contained in:
Aristarkh Zagorodnikov
2019-02-10 23:49:22 +03:00
committed by Ben Adams
parent 9b85871130
commit 8604340a0e
2 changed files with 17 additions and 10 deletions

View File

@@ -129,18 +129,10 @@ namespace System.Diagnostics
/// </summary>
public static string TryGetFullPath(string filePath)
{
try
if (Uri.TryCreate(filePath, UriKind.Absolute, out var uri) && uri.IsFile)
{
var uri = new Uri(filePath);
if (uri.IsFile)
{
return uri.AbsolutePath;
}
return uri.ToString();
return Uri.UnescapeDataString(uri.AbsolutePath);
}
catch (ArgumentException) { }
catch (UriFormatException) { }
return filePath;
}