Skip to content

Commit 783fe06

Browse files
committed
leave relative links alone
1 parent e26f95b commit 783fe06

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

pystac/link.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,19 @@ def get_href(self):
7575
then the HREF returned will be relative.
7676
In all other cases, this method will return an absolute HREF.
7777
"""
78-
href = None
78+
# get the self href
79+
if self.is_resolved():
80+
href = self.target.get_self_href()
81+
else:
82+
href = self.target
83+
84+
# if a hierarchical link with an owner and root, and relative catalog
7985
if self.rel in HIERARCHICAL_LINKS and self.owner is not None:
80-
# get root
8186
root = self.owner.get_root()
82-
if root is not None:
83-
if root.catalog_type in ['RELATIVE_PUBLISHED', 'SELF_CONTAINED']:
84-
if self.is_resolved():
85-
href = self.target.get_self_href()
86-
else:
87-
href = self.target
88-
if href and is_absolute_href(href):
89-
href = make_relative_href(href, self.owner.get_self_href())
90-
if href is None:
91-
href = self.get_absolute_href()
87+
if root is not None and root.catalog_type in ['RELATIVE_PUBLISHED', 'SELF_CONTAINED']:
88+
if href and is_absolute_href(href):
89+
href = make_relative_href(href, self.owner.get_self_href())
90+
9291
return href
9392

9493
def get_absolute_href(self):

tests/data-files/label/label-example-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"links": [
9696
{
9797
"rel": "source",
98-
"href": "http://example.com/area-1-1-imagery/area-1-1-imagery.json",
98+
"href": "../area-1-1-imagery/area-1-1-imagery.json",
9999
"type": "application/json"
100100
}
101101
],

tests/data-files/label/label-example-2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"links": [
8989
{
9090
"rel": "source",
91-
"href": "http://example.com/area-1-1-imagery/area-1-1-imagery.json",
91+
"href": "../area-1-1-imagery/area-1-1-imagery.json",
9292
"type": "application/json"
9393
}
9494
],

0 commit comments

Comments
 (0)