Python tool for converting files and office documents to Markdown.
Reject UNC and Windows device paths (similar to how netlocs are already rejected).
afourneye99a726687ea
diff --git a/packages/markitdown/src/markitdown/_uri_utils.py b/packages/markitdown/src/markitdown/_uri_utils.pyindex b8e18e79..9deb8eca 100644--- a/packages/markitdown/src/markitdown/_uri_utils.py+++ b/packages/markitdown/src/markitdown/_uri_utils.py@@ -1,21 +1,41 @@import base64+import ntpathimport osfrom typing import Tuple, Dictfrom urllib.request import url2pathnamefrom urllib.parse import urlparse, unquote_to_bytes+def _is_unc_or_device_path(path: str) -> bool:+ """Recognize Windows UNC and device namespace prefixes on any platform."""+ drive, _ = ntpath.splitdrive(path)+ return drive.replace("\\", "/").startswith("//")++def file_uri_to_path(file_uri: str) -> Tuple[str | None, str]:- """Convert a file URI to a local file path"""+ """Convert a file URI to a path, rejecting UNC and Windows device paths."""parsed = urlparse(file_uri)if parsed.scheme != "file":raise ValueError(f"Not a file URL: {file_uri}")+ decoded_path = unquote_to_bytes(parsed.path).replace(b"\\", b"/")+ if decoded_path.startswith(b"//"):+ raise ValueError(+ f"Unsupported file URI: {file_uri}. "+ "UNC and Windows device paths are not supported."+ )+netloc = parsed.netloc if parsed.netloc else Nonepath = url2pathname(parsed.path)if os.name == "nt" and path[:1] in "/\\" and path[2:3] == ":":path = path[1:]path = os.path.abspath(path)++ if _is_unc_or_device_path(path):+ raise ValueError(+ f"Unsupported file URI: {file_uri}. "+ "UNC and Windows device paths are not supported."+ )return netloc, path