Skip to content

Commit 34c0981

Browse files
authored
Fix: revert path cleaning (#266)
- Reverted path cleaning changes that removed `./` prefix from relative paths, which was causing compatibility issues with tools like stac-check. The validator now correctly preserves the `./` prefix for relative paths in the current directory.
1 parent a95349e commit 34c0981

File tree

3 files changed

+25
-40
lines changed

3 files changed

+25
-40
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
66

77
## [Unreleased]
88

9+
## [v3.10.1] - 2025-07-26
10+
11+
### Fixed
12+
- Reverted path cleaning changes that removed `./` prefix from relative paths, which was causing compatibility issues with tools like stac-check. The validator now correctly preserves the `./` prefix for relative paths in the current directory. [#266](https://github.com/stac-utils/stac-validator/pull/266)
913

1014
## [v3.10.0] - 2025-07-20
1115

@@ -298,7 +302,8 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
298302
- With the newest version - 1.0.0-beta.2 - items will run through jsonchema validation before the PySTAC validation. The reason for this is that jsonschema will give more informative error messages. This should be addressed better in the future. This is not the case with the --recursive option as time can be a concern here with larger collections.
299303
- Logging. Various additions were made here depending on the options selected. This was done to help assist people to update their STAC collections.
300304

301-
[Unreleased]: https://github.com/sparkgeo/stac-validator/compare/v3.10.0..main
305+
[Unreleased]: https://github.com/sparkgeo/stac-validator/compare/v3.10.1..main
306+
[v3.10.1]: https://github.com/sparkgeo/stac-validator/compare/v3.10.0..v3.10.1
302307
[v3.10.0]: https://github.com/sparkgeo/stac-validator/compare/v3.9.3..v3.10.0
303308
[v3.9.3]: https://github.com/sparkgeo/stac-validator/compare/v3.9.2..v3.9.3
304309
[v3.9.2]: https://github.com/sparkgeo/stac-validator/compare/v3.9.1..v3.9.2

stac_validator/validate.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -684,32 +684,12 @@ def recursive_validator(self, stac_type: str) -> bool:
684684
if link["rel"] in ("child", "item"):
685685
address = link["href"]
686686
if not is_valid_url(address):
687-
if is_valid_url(str(base_url)):
688-
# If base is a URL, handle URL joining
689-
from urllib.parse import urljoin
690-
691-
self.stac_file = urljoin(
692-
(
693-
str(base_url) + "/"
694-
if not str(base_url).endswith("/")
695-
else str(base_url)
696-
),
697-
address,
698-
)
699-
else:
700-
# Handle local file paths
701-
current_dir = os.path.dirname(
702-
os.path.abspath(str(base_url))
703-
)
704-
self.stac_file = os.path.normpath(
705-
os.path.join(current_dir, address)
706-
)
707-
# Convert to relative path for cleaner output if it's under the current working directory
708-
try:
709-
self.stac_file = os.path.relpath(self.stac_file)
710-
except ValueError:
711-
# If paths are on different drives (Windows) or other relpath issues, use the absolute path
712-
pass
687+
path_parts = str(base_url).split("/")
688+
path_parts.pop(-1)
689+
root = path_parts[0]
690+
for i in range(1, len(path_parts)):
691+
root = f"{root}/{path_parts[i]}"
692+
self.stac_file = f"{root}/{address}"
713693
else:
714694
self.stac_file = address
715695

tests/test_recursion.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_recursive_lvl_4_local_v100():
2525
},
2626
{
2727
"version": "1.0.0",
28-
"path": "tests/test_data/local_cat/open-science-catalog-testing/projects/catalog.json",
28+
"path": "tests/test_data/local_cat/open-science-catalog-testing/./projects/catalog.json",
2929
"schema": [
3030
"https://schemas.stacspec.org/v1.0.0/catalog-spec/json-schema/catalog.json"
3131
],
@@ -36,7 +36,7 @@ def test_recursive_lvl_4_local_v100():
3636
},
3737
{
3838
"version": "1.0.0",
39-
"path": "tests/test_data/local_cat/open-science-catalog-testing/projects/3d-earth/collection.json",
39+
"path": "tests/test_data/local_cat/open-science-catalog-testing/./projects/./3d-earth/collection.json",
4040
"schema": [
4141
"https://stac-extensions.github.io/osc/v1.0.0-rc.3/schema.json",
4242
"https://stac-extensions.github.io/contacts/v0.1.1/schema.json",
@@ -49,7 +49,7 @@ def test_recursive_lvl_4_local_v100():
4949
},
5050
{
5151
"version": "1.0.0",
52-
"path": "tests/test_data/local_cat/open-science-catalog-testing/projects/3dctrl/collection.json",
52+
"path": "tests/test_data/local_cat/open-science-catalog-testing/./projects/./3dctrl/collection.json",
5353
"schema": [
5454
"https://stac-extensions.github.io/osc/v1.0.0-rc.3/schema.json",
5555
"https://stac-extensions.github.io/contacts/v0.1.1/schema.json",
@@ -156,7 +156,7 @@ def test_recursion_collection_local_v1rc1():
156156
},
157157
{
158158
"version": "1.0.0-rc.1",
159-
"path": "tests/test_data/1rc1/simple-item.json",
159+
"path": "tests/test_data/1rc1/./simple-item.json",
160160
"schema": [
161161
"https://schemas.stacspec.org/v1.0.0-rc.1/item-spec/json-schema/item.json"
162162
],
@@ -167,7 +167,7 @@ def test_recursion_collection_local_v1rc1():
167167
},
168168
{
169169
"version": "1.0.0-rc.1",
170-
"path": "tests/test_data/1rc1/core-item.json",
170+
"path": "tests/test_data/1rc1/./core-item.json",
171171
"schema": [
172172
"https://schemas.stacspec.org/v1.0.0-rc.1/item-spec/json-schema/item.json"
173173
],
@@ -178,7 +178,7 @@ def test_recursion_collection_local_v1rc1():
178178
},
179179
{
180180
"version": "1.0.0-rc.1",
181-
"path": "tests/test_data/1rc1/extended-item.json",
181+
"path": "tests/test_data/1rc1/./extended-item.json",
182182
"schema": [
183183
"https://cdn.staclint.com/v1.0.0-rc.1/extension/eo.json",
184184
"https://cdn.staclint.com/v1.0.0-rc.1/extension/projection.json",
@@ -212,7 +212,7 @@ def test_recursion_collection_local_v1rc2():
212212
},
213213
{
214214
"version": "1.0.0-rc.2",
215-
"path": "tests/test_data/1rc2/simple-item.json",
215+
"path": "tests/test_data/1rc2/./simple-item.json",
216216
"schema": [
217217
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
218218
],
@@ -223,7 +223,7 @@ def test_recursion_collection_local_v1rc2():
223223
},
224224
{
225225
"version": "1.0.0-rc.2",
226-
"path": "tests/test_data/1rc2/core-item.json",
226+
"path": "tests/test_data/1rc2/./core-item.json",
227227
"schema": [
228228
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
229229
],
@@ -234,7 +234,7 @@ def test_recursion_collection_local_v1rc2():
234234
},
235235
{
236236
"version": "1.0.0-rc.2",
237-
"path": "tests/test_data/1rc2/extended-item.json",
237+
"path": "tests/test_data/1rc2/./extended-item.json",
238238
"schema": [
239239
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
240240
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
@@ -270,7 +270,7 @@ def test_recursion_collection_local_2_v1rc2():
270270
},
271271
{
272272
"version": "1.0.0-rc.2",
273-
"path": "tests/test_data/1rc2/extensions-collection/proj-example/proj-example.json",
273+
"path": "tests/test_data/1rc2/extensions-collection/./proj-example/proj-example.json",
274274
"schema": [
275275
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
276276
],
@@ -298,7 +298,7 @@ def test_recursion_with_bad_item():
298298
assert stac.message == [
299299
{
300300
"version": "1.0.0",
301-
"path": "tests/test_data/v100/bad-item.json",
301+
"path": "tests/test_data/v100/./bad-item.json",
302302
"schema": [
303303
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
304304
],
@@ -331,7 +331,7 @@ def test_recursion_with_bad_item_trace_recursion():
331331
},
332332
{
333333
"version": "1.0.0",
334-
"path": "tests/test_data/v100/bad-item.json",
334+
"path": "tests/test_data/v100/./bad-item.json",
335335
"schema": [
336336
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
337337
],
@@ -356,7 +356,7 @@ def test_recursion_with_bad_child_collection():
356356
assert stac.message == [
357357
{
358358
"version": "1.0.0",
359-
"path": "tests/test_data/v100/collection-only/bad-collection.json",
359+
"path": "tests/test_data/v100/./collection-only/bad-collection.json",
360360
"schema": [
361361
"https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json"
362362
],

0 commit comments

Comments
 (0)