Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Oct 15, 2025

Problem

The DialogJump function fails when attempting to navigate to root directories (e.g., C:\), throwing a UriFormatException with the message:

Invalid URI: A Dos path must be rooted, for example, 'c:\\'.

This occurs when paths are passed with a file: prefix but without proper URI formatting, such as file:C: (missing the trailing slash).

Root Cause

The CheckPath method in DialogJump.cs was using the Uri constructor directly:

var localPath = path.StartsWith("file:", StringComparison.OrdinalIgnoreCase)
    ? new Uri(path).LocalPath
    : path;

The Uri constructor throws UriFormatException when given malformed file URIs like file:C: (without trailing slash), causing DialogJump to fail for root directories.

Solution

Replaced the direct Uri constructor call with Uri.TryCreate() to gracefully handle malformed URIs:

string localPath;
if (path.StartsWith("file:", StringComparison.OrdinalIgnoreCase))
{
    // Try to create a URI from the path
    if (Uri.TryCreate(path, UriKind.Absolute, out var uri))
    {
        localPath = uri.LocalPath;
    }
    else
    {
        // If URI creation fails, treat it as a regular path
        // by removing the "file:" prefix
        localPath = path.Substring(5);
    }
}
else
{
    localPath = path;
}

This approach:

  • ✅ Handles properly formatted file URIs using the standard Uri.LocalPath property
  • ✅ Gracefully degrades for malformed URIs by stripping the file: prefix
  • ✅ Allows the subsequent Directory.Exists() and File.Exists() checks to determine if the path is valid
  • ✅ Maintains full backward compatibility with existing functionality

Testing

Verified the fix handles various path formats correctly:

  • Root directories: file:C:, file:D: no longer throw exceptions
  • Properly formatted URIs: file:///C:/, file://C:/ continue to work
  • Regular paths: C:\, D:\ work as expected
  • Shell paths: shell:MyComputerFolder continue to work

Fixes #4048

Copilot AI and others added 2 commits October 15, 2025 04:40
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>
@prlabeler prlabeler bot added the bug Something isn't working label Oct 15, 2025
@github-actions github-actions bot added this to the 2.1.0 milestone Oct 15, 2025
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
DialogJump path parsing
Flow.Launcher.Infrastructure/DialogJump/DialogJump.cs
Modified CheckPath to safely handle file: URIs using Uri.TryCreate, fallback to stripped path on failure, and preserve existing existence checks to avoid UriFormatException for root and invalid paths.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • VictoriousRaptor
  • jjw24

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the main change by indicating the fix for a UriFormatException in DialogJump when navigating to root directories. It is specific and concise, allowing teammates to understand the primary purpose at a glance.
Linked Issues Check ✅ Passed The changes directly address the objectives outlined in issue #4048 by preventing the UriFormatException for malformed file URIs, handling various path formats including root directories, and preserving existing functionality. The implementation and associated tests confirm compliance with all specified requirements from the linked issue.
Out of Scope Changes Check ✅ Passed The pull request introduces only the intended modifications to DialogJump.CheckPath for safer URI handling and does not include any unrelated code changes. All edits are clearly scoped to resolving the root directory navigation bug without tangential alterations.
Description Check ✅ Passed The pull request description thoroughly explains the problem, root cause, and solution in relation to the DialogJump function and UriFormatException, demonstrating clear relevance to the changeset. It aligns with the modifications and includes testing scenarios for various path formats.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-dialog-jump-root-directory

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d9ef2c and 21709e8.

📒 Files selected for processing (1)
  • Flow.Launcher.Infrastructure/DialogJump/DialogJump.cs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-03T07:40:11.014Z
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3057
File: Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs:0-0
Timestamp: 2024-11-03T07:40:11.014Z
Learning: In Flow Launcher, when using Windows Forms dialogs (e.g., in `JsonRPCPluginSettings.cs`), path validation is enabled by default in `OpenFileDialog` and `FolderBrowserDialog`, preventing users from selecting invalid paths, but it's possible to opt out of this validation on individual dialogs.

Applied to files:

  • Flow.Launcher.Infrastructure/DialogJump/DialogJump.cs
⏰ 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)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (1)
Flow.Launcher.Infrastructure/DialogJump/DialogJump.cs (1)

831-849: URI parsing fix is correct; ensure test coverage and review related URI usages.

  • Add unit tests for CheckPath covering file: edge cases (file:, file:C:, file:///C:/, non-file: paths).
  • Scan other new Uri(...) usages to confirm malformed inputs are handled without exceptions.
  • Optional: replace path.Substring(5) with path.Length > 5 ? path.Substring(5) : string.Empty for explicit safety.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

gitstream-cm bot commented Oct 15, 2025

🥷 Code experts: taooceros

taooceros has most 👩‍💻 activity in the files.
taooceros has most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/DialogJump/DialogJump.cs

Activity based on git-commit:

taooceros
OCT
SEP
AUG
JUL 1079 additions & 0 deletions
JUN
MAY

Knowledge based on git-blame:
taooceros: 99%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

Copy link

gitstream-cm bot commented Oct 15, 2025

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
Copy link

gitstream-cm bot commented Oct 15, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

@Jack251970 Jack251970 enabled auto-merge October 15, 2025 05:03
@jjw24 jjw24 disabled auto-merge October 15, 2025 09:11
@jjw24 jjw24 enabled auto-merge (squash) October 15, 2025 09:11
@jjw24 jjw24 merged commit 3690042 into dev Oct 15, 2025
24 checks passed
@jjw24 jjw24 deleted the copilot/fix-dialog-jump-root-directory branch October 15, 2025 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Dialog Jump does not work in the root directory

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.