Skip to content

Commit 334e314

Browse files
committed
Just strip off the leading slash
1 parent d34dc2d commit 334e314

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

pystac/link.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def get_href(self, transform_href: bool = True) -> str | None:
172172
href = self._target_object.get_self_href()
173173
else:
174174
href = self._target_href
175-
print("starting href:", href)
176175

177176
if (
178177
transform_href
@@ -192,7 +191,6 @@ def get_href(self, transform_href: bool = True) -> str | None:
192191
owner_href = self.owner.get_self_href()
193192
if owner_href is not None:
194193
href = make_relative_href(href, owner_href)
195-
print("new href:", href)
196194
return href
197195

198196
@property

pystac/utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ def safe_urlparse(href: str) -> URLParseResult:
5050
Returns:
5151
urllib.parse.ParseResult : The named tuple representing the parsed HREF.
5252
"""
53-
print("href:", href)
5453
parsed = urlparse(href)
55-
print(parsed.scheme, parsed.netloc, parsed.path)
5654
if parsed.scheme != "" and (
5755
href.lower().startswith(f"{parsed.scheme}:\\")
5856
or (
5957
href.lower().startswith(f"{parsed.scheme}:/")
6058
and not href.lower().startswith(f"{parsed.scheme}://")
6159
)
6260
):
63-
output = URLParseResult(
61+
return URLParseResult(
6462
scheme="",
6563
netloc="",
6664
path="{}:{}".format(
@@ -73,19 +71,22 @@ def safe_urlparse(href: str) -> URLParseResult:
7371
query=parsed.query,
7472
fragment=parsed.fragment,
7573
)
76-
print("non-file scheme gives:", output.path)
77-
return output
78-
if parsed.scheme == "file" and parsed.netloc:
79-
output = URLParseResult(
74+
if parsed.scheme == "file":
75+
# Windows drives sometimes get parsed as the netloc and sometimes
76+
# as part of the parsed.path.
77+
if parsed.netloc:
78+
path = f"{parsed.netloc}{parsed.path}"
79+
elif parsed.path.startswith("/") and os.name == "nt":
80+
path = parsed.path[1:]
81+
82+
return URLParseResult(
8083
scheme=parsed.scheme,
8184
netloc="",
82-
path=f"{parsed.netloc}{parsed.path}",
85+
path=path,
8386
params=parsed.params,
8487
query=parsed.query,
8588
fragment=parsed.fragment,
8689
)
87-
print("file scheme gives:", output.path)
88-
return output
8990
else:
9091
return parsed
9192

0 commit comments

Comments
 (0)