Skip to content

Commit d8219ee

Browse files
authored
Merge pull request #208 from stac-utils/fix/180
Allow for unnormalized path prefixes like /vsitar/
2 parents 8fb3140 + 846eefb commit d8219ee

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pystac/utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def make_absolute_href(source_href, start_href=None, start_is_dir=False):
108108
else:
109109
start_dir = _pathlib.dirname(parsed_start.path)
110110
abs_path = _pathlib.abspath(_join(is_path, start_dir, parsed_source.path))
111+
112+
# Account for the normalization of abspath for
113+
# things like /vsitar// prefixes by replacing the
114+
# original start_dir text when abspath modifies the start_dir.
115+
if not start_dir == _pathlib.abspath(start_dir):
116+
abs_path = abs_path.replace(_pathlib.abspath(start_dir), start_dir)
117+
111118
if parsed_start.scheme != '':
112119
if not is_path:
113120
abs_path = abs_path.replace('\\', '/')

tests/test_utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def test_make_absolute_href(self):
7979
actual = make_absolute_href(source_href, start_href)
8080
self.assertEqual(actual, expected)
8181

82+
def test_make_absolute_href_on_vsitar(self):
83+
rel_path = 'some/item.json'
84+
cat_path = '/vsitar//tmp/catalog.tar/catalog.json'
85+
expected = '/vsitar//tmp/catalog.tar/some/item.json'
86+
87+
self.assertEqual(expected, make_absolute_href(rel_path, cat_path))
88+
8289
def test_make_absolute_href_windows(self):
8390
utils._pathlib = ntpath
8491
try:

0 commit comments

Comments
 (0)