File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,12 @@ def make_path_safe(path):
252252 if "\\ .." in path or "..\\ " in path :
253253 raise ValueError (f"unexpected '..' element in path { path !r} " )
254254
255+ path = slashify (path )
256+
257+ if is_win32 and len (path ) >= 2 and path [1 ] == ":" :
258+ # Handle drive letters: C:/path -> C/path
259+ path = path [0 ].upper () + path [2 :]
260+
255261 path = map_chars (path )
256262
257263 path = path .lstrip ("/" )
Original file line number Diff line number Diff line change @@ -318,6 +318,23 @@ def test_invalid_make_path_safe(path):
318318 make_path_safe (path )
319319
320320
321+ def test_make_path_safe_win32_drive_letters (monkeypatch ):
322+ monkeypatch .setattr ("borg.helpers.fs.is_win32" , True )
323+ # Basic drive letter
324+ assert make_path_safe ("C:\\ Users" ) == "C/Users"
325+ assert make_path_safe ("C:\\ Users\\ test" ) == "C/Users/test"
326+ # Lowercase drive letter -> Uppercase
327+ assert make_path_safe ("c:\\ windows" ) == "C/windows"
328+ # Relative path with backslashes
329+ assert make_path_safe ("foo\\ bar" ) == "foo/bar"
330+ # Just drive letter
331+ assert make_path_safe ("D:" ) == "D"
332+ # Drive letter with forward slash
333+ assert make_path_safe ("E:/test" ) == "E/test"
334+ # Mixed separators
335+ assert make_path_safe ("F:\\ Mixed/Separators" ) == "F/Mixed/Separators"
336+
337+
321338def test_dir_is_tagged (tmpdir ):
322339 """Test dir_is_tagged with both path-based and file descriptor-based operations."""
323340
You can’t perform that action at this time.
0 commit comments