Skip to content

Commit efa89d3

Browse files
committed
refactor: simplify path quoting to always add quotes
- Rename escape_path_if_needed to quote_path - Remove space-checking logic, always quote paths - Update tests to reflect simplified behavior
1 parent f9bc117 commit efa89d3

File tree

2 files changed

+17
-38
lines changed

2 files changed

+17
-38
lines changed

src/debugger.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ impl Debugger {
156156
DownloadedFileType::Uncompressed,
157157
)
158158
.map_err(|err| {
159-
format!(
160-
"Failed to download java-debug fork from {JAVA_DEBUG_PLUGIN_FORK_URL}: {err}"
161-
)
159+
format!("Failed to download java-debug fork from {JAVA_DEBUG_PLUGIN_FORK_URL}: {err}")
162160
})?;
163161

164162
self.plugin_path = Some(jar_path.clone());
@@ -196,9 +194,7 @@ impl Debugger {
196194
return Err(err.to_owned());
197195
}
198196

199-
println!(
200-
"Could not fetch debugger: {err}\nFalling back to local version."
201-
);
197+
println!("Could not fetch debugger: {err}\nFalling back to local version.");
202198

203199
let exists = fs::read_dir(prefix)
204200
.ok()

src/util.rs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn path_to_string<P: AsRef<Path>>(path: P) -> zed::Result<String> {
264264
.to_path_buf()
265265
.into_os_string()
266266
.into_string()
267-
.map(escape_path_if_needed)
267+
.map(quote_path)
268268
.map_err(|_| PATH_TO_STR_ERROR.to_string())
269269
}
270270

@@ -347,29 +347,26 @@ pub fn should_use_local_or_download(
347347
}
348348
}
349349

350-
// Escape path if included spaces
351-
// Add quotes to path if needed for avoid errors with spaces in path
352-
//
353-
// # Arguments
354-
// * `path` - The path to escape
355-
//
356-
// # Returns
357-
// * `String` - The escaped path
358-
//
359-
fn escape_path_if_needed(path: String) -> String {
360-
if path.contains(' ') {
361-
format!("\"{}\"", path)
362-
} else {
363-
path
364-
}
350+
/// Quotes a path string to handle spaces safely
351+
///
352+
/// Wraps the path in double quotes to prevent errors when the path
353+
/// contains spaces or special characters.
354+
///
355+
/// # Arguments
356+
/// * `path` - The path to quote
357+
///
358+
/// # Returns
359+
/// A `String` containing the quoted path
360+
fn quote_path(path: String) -> String {
361+
format!("\"{}\"", path)
365362
}
366363

367364
#[cfg(test)]
368365
mod tests {
369366
use super::*;
370367

371368
#[test]
372-
fn test_path_to_string_with_spaces_windows() {
369+
fn test_path_to_quoted_string_windows() {
373370
let path = PathBuf::from("C:\\Users\\User Name\\Projects\\zed-extension-java");
374371
let escaped = path_to_string(&path).unwrap();
375372
assert_eq!(
@@ -379,23 +376,9 @@ mod tests {
379376
}
380377

381378
#[test]
382-
fn test_path_to_string_without_spaces_windows() {
383-
let path = PathBuf::from("C:\\Users\\UserName\\Projects\\zed-extension-java");
384-
let escaped = path_to_string(&path).unwrap();
385-
assert_eq!(escaped, "C:\\Users\\UserName\\Projects\\zed-extension-java");
386-
}
387-
388-
#[test]
389-
fn test_path_to_string_with_spaces_unix() {
379+
fn test_path_to_quoted_string_unix() {
390380
let path = PathBuf::from("/home/username/Projects/zed extension java");
391381
let escaped = path_to_string(&path).unwrap();
392382
assert_eq!(escaped, "\"/home/username/Projects/zed extension java\"");
393383
}
394-
395-
#[test]
396-
fn test_path_to_string_without_spaces_unix() {
397-
let path = PathBuf::from("/home/username/Projects/zed-extension-java");
398-
let escaped = path_to_string(&path).unwrap();
399-
assert_eq!(escaped, "/home/username/Projects/zed-extension-java");
400-
}
401384
}

0 commit comments

Comments
 (0)