-
-
Notifications
You must be signed in to change notification settings - Fork 447
Fix DialogJump UriFormatException when navigating to root directories #4052
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
Conversation
Replace new Uri() with Uri.TryCreate() to handle malformed file: URIs gracefully. When file: prefix is present but URI parsing fails (e.g., "file:C:" without trailing slash), the code now strips the prefix and uses the path directly instead of throwing an exception. Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
📝 WalkthroughWalkthroughAdds guarded parsing for file: URI inputs in DialogJump.CheckPath. If the path starts with file:, it tries Uri.TryCreate and uses LocalPath on success; otherwise, it strips the prefix and treats it as a normal path. Non-file: inputs are unchanged. Subsequent directory/file existence checks remain the same. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as Caller
participant DJ as DialogJump.CheckPath
participant FS as FileSystem
U->>DJ: CheckPath(path)
alt path starts with "file:"
DJ->>DJ: TryCreate Uri from path
alt URI valid
DJ->>DJ: localPath = uri.LocalPath
else URI invalid
DJ->>DJ: localPath = strip "file:" prefix
end
else not "file:"
DJ->>DJ: localPath = path
end
DJ->>FS: Directory.Exists(localPath)?
alt Directory exists
DJ-->>U: success (file=false)
else
DJ->>FS: File.Exists(localPath)?
alt File exists
DJ-->>U: success (file=true)
else
DJ-->>U: not found
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2024-11-03T07:40:11.014Z
Applied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🥷 Code experts: taooceros taooceros has most 👩💻 activity in the files. See details
Activity based on git-commit:
Knowledge based on git-blame: ✨ Comment |
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
1 similar comment
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
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 #4048