diff --git a/src/citrine/__version__.py b/src/citrine/__version__.py index 0c11babd0..dae42b1bd 100644 --- a/src/citrine/__version__.py +++ b/src/citrine/__version__.py @@ -1 +1 @@ -__version__ = "3.5.1" +__version__ = "3.5.2" diff --git a/src/citrine/resources/file_link.py b/src/citrine/resources/file_link.py index ca95ae2dd..537386ad8 100644 --- a/src/citrine/resources/file_link.py +++ b/src/citrine/resources/file_link.py @@ -4,7 +4,8 @@ from pathlib import Path from tempfile import TemporaryDirectory from typing import Optional, Tuple, Union, Dict, Iterable, Sequence -from urllib.parse import urlparse, unquote_plus +from urllib.parse import urlparse +from urllib.request import url2pathname from uuid import UUID from citrine._rest.collection import Collection @@ -647,7 +648,11 @@ def read(self, *, file_link: Union[str, UUID, FileLink]) -> bytes: file_link = self._resolve_file_link(file_link) if self._is_local_url(file_link.url): # Read the local file - path = Path(unquote_plus(urlparse(file_link.url).path)) + parsed_url = urlparse(file_link.url) + if parsed_url.netloc not in {'', '.', 'localhost'}: + raise ValueError("Non-local UNCs (e.g., Windows network paths) are not supported.") + # Space should have been encoded as %20, but just in case it was a + + path = Path(url2pathname(parsed_url.path.replace('+', '%20'))) return path.read_bytes() if self._is_external_url(file_link.url): # Pull it from where ever it lives diff --git a/tests/resources/test_file_link.py b/tests/resources/test_file_link.py index 49218cf79..1b10585e1 100644 --- a/tests/resources/test_file_link.py +++ b/tests/resources/test_file_link.py @@ -837,3 +837,6 @@ def test_exceptions(collection: FileCollection, session): ) with pytest.raises(NotFound): collection.get(uid="name") + + with pytest.raises(ValueError, match="Windows"): + collection.read(file_link=FileLink('File', 'file://remote/network/file.txt'))