bundle catalog add rewrites Windows drive paths as POSIX paths

未關閉 適合新手
#5,204 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@chelsealong 已經在處理了。

開始於 2026年11月1日。

  • #5205 來自 @chelsealong —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
68/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cli

研究方向

從 src/specify_cli/bundles/catalog_config.py 中的 _is_local_path 和 _canonicalize_url 開始,追蹤 add_source()(約第 184 行)如何儲存結果。Windows 磁碟機路徑在 POSIX 上不應經過主機原生的 Path(...).resolve();要麼原樣保留該值,要麼拒絕它。完成標準是 bundle catalog add C:\catalog.json 不再寫入相對於目前工作目錄的 URL,並為此情況新增測試。

由索引模型根據 Issue 內容生成。

描述

triage-must-have

Summary

_is_local_path() explicitly recognizes a Windows drive path such as
C:\catalog.json, but _canonicalize_url() then passes it to the host-native
Path(...).resolve(). On Linux and macOS that turns the Windows absolute path
into a path relative to the current project, and add_source() persists the
rewritten value into the catalog configuration.

Environment

  • Repository: github/spec-kit
  • Target revision: 1c799bda6c136fcf42fb3475a922ccaac57e6c71
  • Platform: macOS (POSIX), Python 3.13
  • File: src/specify_cli/bundles/catalog_config.py:96-116
    (_is_local_path, _canonicalize_url), used by add_source() at :184

Expected behavior

A Windows absolute path is either preserved verbatim in the configuration or
rejected as non-local on a POSIX host. It must not be silently rewritten into a
different path.

Actual behavior

Adding C:\catalog.json on macOS persists:

catalogs:
- id: c---catalog
  url: /private/tmp/.../project/C:\catalog.json
  priority: 50
  install_policy: install-allowed

The stored URL points at a non-existent file whose name contains a backslash
and a colon; later catalog reads fail to resolve the intended source.

Root cause

_WINDOWS_DRIVE_RE = re.compile(r"^[A-Za-z]:[\\/]")

def _is_local_path(url: str) -> bool:
    if _WINDOWS_DRIVE_RE.match(url):
        return True
    ...

def _canonicalize_url(url: str) -> str:
    if _is_local_path(url):
        return str(Path(url).expanduser().resolve())
    return url

The Windows-drive branch is platform-independent, while Path is host-native.
On POSIX, Path(r"C:\catalog.json").resolve() produces
<cwd>/C:\catalog.json; on Windows it would be absolute. The same function is
reached from the public bundle catalog add path through add_source().

Impact

  • A catalog configuration produced on Windows and consumed on Linux/macOS (or a
    Windows path passed on a POSIX host) is silently corrupted instead of being
    rejected.
  • The stored catalog id (c---catalog) and URL both diverge from the user's
    input, and the source cannot be loaded.

Suggested fix

Preserve Windows drive paths on non-Windows hosts instead of resolving them
with the host-native Path:

def _canonicalize_url(url: str) -> str:
    if _WINDOWS_DRIVE_RE.match(url):
        return url            # do not reinterpret on POSIX
    if _is_local_path(url):
        return str(Path(url).expanduser().resolve())
    return url

or canonicalize with PureWindowsPath when the host is POSIX and the input
matches the Windows-drive form, and reject the value if it cannot be resolved.

主要語言
Python
星號
144k
分支
12.9k
平均合併
1 天 4 小時
30 天內合併 PR
181

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

github/spec-kit 的其他 Issue

查看 github/spec-kit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。