Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(['/', '\\'])

Copy link
Copy Markdown

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_path treats the backslashes as directory separators, and update_completion immediately passes the resulting directory to read_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
In `src/util.rs` at line 394:

**Backslash UNC input initiates SMB access**

When a Windows user types or pastes an attacker-provided `\\host\share\...` path into the input, `split_completion_path` treats the backslashes as directory separators, and `update_completion` immediately passes the resulting directory to `read_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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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();
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 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.

Prompt for AI agents
In `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()));
Expand Down