Skip to content

Commit 69d0f1f

Browse files
authored
Merge pull request #950 from CitrineInformatics/feature/pne-203-file-links-on-windows
[PNE-203] Fix reading file links on Windows.
2 parents 8d17d52 + 6665ba7 commit 69d0f1f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/citrine/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.5.1"
1+
__version__ = "3.5.2"

src/citrine/resources/file_link.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from pathlib import Path
55
from tempfile import TemporaryDirectory
66
from typing import Optional, Tuple, Union, Dict, Iterable, Sequence
7-
from urllib.parse import urlparse, unquote_plus
7+
from urllib.parse import urlparse
8+
from urllib.request import url2pathname
89
from uuid import UUID
910

1011
from citrine._rest.collection import Collection
@@ -647,7 +648,11 @@ def read(self, *, file_link: Union[str, UUID, FileLink]) -> bytes:
647648
file_link = self._resolve_file_link(file_link)
648649

649650
if self._is_local_url(file_link.url): # Read the local file
650-
path = Path(unquote_plus(urlparse(file_link.url).path))
651+
parsed_url = urlparse(file_link.url)
652+
if parsed_url.netloc not in {'', '.', 'localhost'}:
653+
raise ValueError("Non-local UNCs (e.g., Windows network paths) are not supported.")
654+
# Space should have been encoded as %20, but just in case it was a +
655+
path = Path(url2pathname(parsed_url.path.replace('+', '%20')))
651656
return path.read_bytes()
652657

653658
if self._is_external_url(file_link.url): # Pull it from where ever it lives

tests/resources/test_file_link.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,6 @@ def test_exceptions(collection: FileCollection, session):
837837
)
838838
with pytest.raises(NotFound):
839839
collection.get(uid="name")
840+
841+
with pytest.raises(ValueError, match="Windows"):
842+
collection.read(file_link=FileLink('File', 'file://remote/network/file.txt'))

0 commit comments

Comments
 (0)