Skip to content

Commit 0ee1c7e

Browse files
committed
Correctly handle UNC file URIs on Windows
1 parent b5b50d4 commit 0ee1c7e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

domdf_python_tools/paths.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import json
4949
import os
5050
import pathlib
51-
import platform
5251
import shutil
5352
import stat
5453
import sys
@@ -849,13 +848,25 @@ def from_uri(cls: Type[_PP], uri: str) -> _PP:
849848

850849
if parseresult.scheme != "file":
851850
raise ValueError(f"Unsupported URI scheme {parseresult.scheme!r}")
852-
if parseresult.netloc or parseresult.params or parseresult.query or parseresult.fragment:
851+
if parseresult.params or parseresult.query or parseresult.fragment:
853852
raise ValueError("Malformed file URI")
854853

855-
path = urllib.parse.unquote_to_bytes(parseresult.path).decode("UTF-8")
854+
if sys.platform == "win32":
856855

857-
if os.name == "nt":
858-
path = path.lstrip('/')
856+
if parseresult.netloc:
857+
path = ''.join([
858+
"//",
859+
urllib.parse.unquote_to_bytes(parseresult.netloc).decode("UTF-8"),
860+
urllib.parse.unquote_to_bytes(parseresult.path).decode("UTF-8"),
861+
])
862+
else:
863+
path = urllib.parse.unquote_to_bytes(parseresult.path).decode("UTF-8").lstrip('/')
864+
865+
else:
866+
if parseresult.netloc:
867+
raise ValueError("Malformed file URI")
868+
869+
path = urllib.parse.unquote_to_bytes(parseresult.path).decode("UTF-8")
859870

860871
return cls(path)
861872

0 commit comments

Comments
 (0)