Fix DialogJump UriFormatException when navigating to root directories #4050
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The DialogJump function fails when attempting to navigate to root directories (e.g.,
C:\
), throwing aUriFormatException
with the message:This occurs when paths are passed with a
file:
prefix but without proper URI formatting, such asfile:C:
(missing the trailing slash).Root Cause
The
CheckPath
method inDialogJump.cs
was using theUri
constructor directly:The
Uri
constructor throwsUriFormatException
when given malformed file URIs likefile:C:
(without trailing slash), causing DialogJump to fail for root directories.Solution
Replaced the direct
Uri
constructor call withUri.TryCreate()
to gracefully handle malformed URIs:This approach:
Uri.LocalPath
propertyfile:
prefixDirectory.Exists()
andFile.Exists()
checks to determine if the path is validTesting
Verified the fix handles various path formats correctly:
file:C:
,file:D:
no longer throw exceptionsfile:///C:/
,file://C:/
continue to workC:\
,D:\
work as expectedshell:MyComputerFolder
continue to workFixes #[issue_number]
Original prompt
Fixes #4048
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.