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
39 changes: 26 additions & 13 deletions crates/forge_main/src/zsh/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,18 @@ fn resolve_file_path(candidate: &str) -> Option<String> {
/// Returns the byte offset of the first unescaped whitespace character, or
/// the length of `input` if no unescaped whitespace is found.
fn find_token_end(input: &str) -> usize {
let bytes = input.as_bytes();
let mut i = 0;
while i < bytes.len() {
if bytes.get(i) == Some(&b'\\') && i + 1 < bytes.len() {
// Skip escaped character
i += 2;
} else if bytes
.get(i)
.map(|b| (*b as char).is_whitespace())
.unwrap_or(false)
{
let mut escaped = false;
for (i, c) in input.char_indices() {
if escaped {
escaped = false;
continue;
}
if c == '\\' {
escaped = true;
continue;
}
if c.is_whitespace() {
return i;
} else {
i += 1;
}
}
input.len()
Expand Down Expand Up @@ -208,6 +206,14 @@ mod tests {

use super::*;

#[test]
fn test_wrap_pasted_text_cjk_no_paths() {
let fixture = "公";
let actual = wrap_pasted_text(fixture);
let expected = "公";
assert_eq!(actual, expected);
}

#[test]
fn test_wrap_pasted_text_no_paths() {
let fixture = "hello world";
Expand Down Expand Up @@ -470,6 +476,13 @@ mod tests {
assert_eq!(actual, expected);
}

#[test]
fn test_find_token_end_backslash_escaped_space() {
let actual = find_token_end("/path/my\\ file.txt please");
let expected = "/path/my\\ file.txt".len();
assert_eq!(actual, expected);
}

#[test]
fn test_resolve_file_path_plain() {
let actual = resolve_file_path("/usr/bin/env");
Expand Down
Loading