Skip to content

Commit 738fc22

Browse files
authored
fix: preserve Windows drive paths in bundle catalog config (#5205)
1 parent 4fed943 commit 738fc22

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/specify_cli/bundles/catalog_config.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def _canonicalize_url(url: str) -> str:
110110
111111
Remote URLs (``http(s)://``, ``file://``, ``builtin://``) are returned
112112
unchanged; only bare/relative local paths are resolved to an absolute path.
113+
Foreign Windows drive paths stay unchanged rather than becoming POSIX paths.
113114
"""
115+
if _WINDOWS_DRIVE_RE.match(url) and not Path(url).is_absolute():
116+
return url
114117
if _is_local_path(url):
115118
return str(Path(url).expanduser().resolve())
116119
return url

‎tests/specify_cli/bundles/test_catalog_config.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Unit tests for project catalog-config id derivation and url canonicalization."""
22
from __future__ import annotations
33

4+
import os
45
from pathlib import Path
56

67
import pytest
@@ -72,6 +73,28 @@ def test_add_source_persists_absolute_local_path(tmp_path: Path, monkeypatch):
7273
assert Path(source.url) == catalog.resolve()
7374

7475

76+
@pytest.mark.skipif(os.name == "nt", reason="POSIX path rewriting regression")
77+
@pytest.mark.parametrize("url", [r"C:\catalog.json", "C:/catalog.json"])
78+
def test_add_source_preserves_foreign_windows_drive_path(tmp_path: Path, url: str):
79+
project = tmp_path / "proj"
80+
project.mkdir()
81+
82+
source, status = cc.add_source(
83+
project, url, policy="install-allowed", priority=50
84+
)
85+
86+
assert status == "added"
87+
assert source.url == url
88+
assert cc._read(project)[0]["url"] == url
89+
repeated, status = cc.add_source(
90+
project, url, policy="install-allowed", priority=50
91+
)
92+
assert status == "unchanged"
93+
assert repeated.url == url
94+
cc.remove_source(project, url)
95+
assert cc._read(project) == []
96+
97+
7598
def test_add_source_normalizes_existing_entry_for_idempotency(tmp_path: Path):
7699
project = tmp_path / "proj"
77100
(project / ".specify").mkdir(parents=True)

0 commit comments

Comments
 (0)