@@ -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) ]
368365mod 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