@@ -42,8 +42,12 @@ fn normalize_case_windows(path: &Path) -> Option<PathBuf> {
4242 use std:: os:: windows:: ffi:: { OsStrExt , OsStringExt } ;
4343 use windows_sys:: Win32 :: Storage :: FileSystem :: GetLongPathNameW ;
4444
45+ // Normalize forward slashes to backslashes (canonicalize did this)
46+ let path_str = path. to_string_lossy ( ) . replace ( '/' , "\\ " ) ;
47+ let normalized_path = PathBuf :: from ( & path_str) ;
48+
4549 // Convert path to wide string (UTF-16) with null terminator
46- let wide_path: Vec < u16 > = path
50+ let wide_path: Vec < u16 > = normalized_path
4751 . as_os_str ( )
4852 . encode_wide ( )
4953 . chain ( std:: iter:: once ( 0 ) )
@@ -76,7 +80,7 @@ fn normalize_case_windows(path: &Path) -> Option<PathBuf> {
7680
7781 // Remove UNC prefix if original path didn't have it
7882 // GetLongPathNameW may add \\?\ prefix in some cases
79- let original_has_unc = path . to_string_lossy ( ) . starts_with ( r"\\?\" ) ;
83+ let original_has_unc = path_str . starts_with ( r"\\?\" ) ;
8084 if result_str. starts_with ( r"\\?\" ) && !original_has_unc {
8185 result_str = result_str. trim_start_matches ( r"\\?\" ) . to_string ( ) ;
8286 }
@@ -317,4 +321,22 @@ mod tests {
317321 root_result
318322 ) ;
319323 }
324+
325+ #[ test]
326+ #[ cfg( windows) ]
327+ fn test_norm_case_windows_normalizes_slashes ( ) {
328+ // norm_case should convert forward slashes to backslashes (like canonicalize did)
329+ let path_with_forward_slashes = PathBuf :: from ( "C:/Windows/System32" ) ;
330+ let result = norm_case ( & path_with_forward_slashes) ;
331+ assert ! (
332+ !result. to_string_lossy( ) . contains( '/' ) ,
333+ "Should convert forward slashes to backslashes, got: {:?}" ,
334+ result
335+ ) ;
336+ assert ! (
337+ result. to_string_lossy( ) . contains( '\\' ) ,
338+ "Should have backslashes, got: {:?}" ,
339+ result
340+ ) ;
341+ }
320342}
0 commit comments