Repository navigation
fix: support Windows path completion #7
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,17 +389,26 @@ fn extension_bonus(name: &str) -> i32 { | |
| /// prefix does not match exactly so you can keep drilling down. capped at 64 | ||
| /// because nobody benefits from a list that fills the screen, and directory | ||
| /// reads are not free. | ||
| fn split_completion_path(input: &str, windows: bool) -> (&str, &str) { | ||
| let separator = if windows { | ||
| input.rfind(['/', '\\']) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Drive-relative suggestions are missing When a Windows user enters a drive-relative path such as Handle the drive prefix as the directory for drive-relative paths in Also at Prompt for AI agentsIn `src/util.rs` at line 394:
**Drive-relative suggestions are missing**
When a Windows user enters a drive-relative path such as `C:rec` with no separator, `split_completion_path` returns an empty directory and keeps the drive-qualified text as the filename prefix, so `complete_path` scans the process’s current directory and returns no useful suggestions; accepted suggestions also resolve from the wrong directory.
Handle the drive prefix as the directory for drive-relative paths in `split_completion_path`.
Also at `src/util.rs:400-401`.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Backslash home paths return no candidates When a Windows user enters a home-relative path using Expand tilde paths using Windows backslashes as well as forward slashes. Prompt for AI agentsIn `src/util.rs` at line 394:
**Backslash home paths return no candidates**
When a Windows user enters a home-relative path using `~\`, `expand_tilde` leaves the backslash form unchanged, so `complete_path` scans a literal `~\` path and returns no candidates.
Expand tilde paths using Windows backslashes as well as forward slashes. |
||
| } else { | ||
| input.rfind('/') | ||
| }; | ||
| match separator { | ||
| Some(i) => (&input[..=i], &input[i + 1..]), | ||
| None => ("", input), | ||
| } | ||
| } | ||
|
|
||
| pub fn complete_path(input: &str) -> Vec<CompletionCandidate> { | ||
| let raw = if input.starts_with('~') { | ||
| expand_tilde(input) | ||
| } else { | ||
| PathBuf::from(input) | ||
| }; | ||
| let text = raw.to_string_lossy().to_string(); | ||
| let (dir, prefix) = match text.rfind('/') { | ||
| Some(i) => (&text[..=i], &text[i + 1..]), | ||
| None => ("", text.as_str()), | ||
| }; | ||
| let (dir, prefix) = split_completion_path(&text, cfg!(windows)); | ||
| let scan = if dir.is_empty() { "." } else { dir }; | ||
| let scan = expand_tilde(scan); | ||
| let mut out: Vec<CompletionCandidate> = Vec::new(); | ||
|
|
@@ -812,6 +821,22 @@ mod tests { | |
| assert_eq!(common_prefix(&mixed), "éc"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn completion_path_splits_native_and_windows_separators() { | ||
| assert_eq!( | ||
| split_completion_path("/home/user/rec", false), | ||
| ("/home/user/", "rec") | ||
| ); | ||
| assert_eq!( | ||
| split_completion_path("C:\\Users\\user\\rec", true), | ||
| ("C:\\Users\\user\\", "rec") | ||
| ); | ||
|
Comment on lines
+831
to
+833
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Windows wiring regression goes undetected When Add a test that exercises Prompt for AI agentsIn `src/util.rs` at lines 831-833:
**Windows wiring regression goes undetected**
When `complete_path` is wired to use the non-Windows separator mode, `completion_path_splits_native_and_windows_separators` calls `split_completion_path` directly with `true`, so it passes even if `complete_path` stops enabling Windows separators and Windows path completion remains broken.
Add a test that exercises `complete_path` with a Windows-style path and verifies the resulting directory and candidates. |
||
| assert_eq!( | ||
| split_completion_path("C:/Users/user/rec", true), | ||
| ("C:/Users/user/", "rec") | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn complete_ranks_and_marks_dirs() { | ||
| let dir = std::env::temp_dir().join(format!("scribe_cmpl_{}", std::process::id())); | ||
|
|
||
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.
🟡 Medium · Backslash UNC input initiates SMB access
When a Windows user types or pastes an attacker-provided
\\host\share\...path into the input,split_completion_pathtreats the backslashes as directory separators, andupdate_completionimmediately passes the resulting directory toread_dir; Windows attempts SMB authentication using the user's ambient credentials before the user accepts the candidate.Avoid automatically enumerating UNC paths while the user types; require a deliberate action before accessing a remote share.
Prompt for AI agents