create_or_update_file writes to the wrong file when the path contains # or ?
維護者通常 4 天內回覆
評估
研究方向
從 pkg/github/repositories.go 中的 CreateOrUpdateFile(v1.14.0 / 71ef8266)開始,此處 CreateFile 呼叫未經轉義地傳入 path,並閱讀 escapeGitTreeish 作為逐段轉義的既有模式。與基於 GetContents 的存在性檢查和 symlink 檢查相比較,後者已正確轉義。完成的樣貌是在 mock 伺服器上發出 PUT /repos/{owner}/{repo}/contents/docs/C%23/intro.md,再加上一個回歸測試(擴充既有的 repositories 測試檔案),斷言 # 和 ? 路徑會寫入正確的檔案。
由索引模型根據 Issue 內容生成。
描述
Describe the bug
create_or_update_file with path: "docs/C#/intro.md" commits the content to a file named docs/C and reports success. A ? does the same (notes/what?.md is written as notes/what).
The path goes into the request URL unescaped: go-github's RepositoriesService.CreateFile builds repos/{owner}/{repo}/contents/{path} with no escaping, so everything from # on becomes a URL fragment and everything from ? on becomes a query string. The checks that run first (the existing-file / SHA lookup and the symlink check) go through GetContents, which does escape the path, so they look at the right file while the write goes to another.
Affected version
v1.14.0 and main at 71ef8266 (pkg/github/repositories.go, the CreateFile call in CreateOrUpdateFile).
Steps to reproduce the behavior
- Call
create_or_update_fileon a test repository:{"owner":"<you>","repo":"<test repo>","path":"docs/C#/intro.md","content":"# Intro","message":"Add intro","branch":"main"} - Look at the commit.
Expected vs actual behavior
Expected: a file at docs/C#/intro.md (the request goes to PUT /repos/<you>/<test repo>/contents/docs/C%23/intro.md).
Actual: the request goes to PUT /repos/<you>/<test repo>/contents/docs/C, the commit creates a file named docs/C, and the tool result reports success with "path": "docs/C". If docs/C already exists as a file, it is overwritten.
Logs
Request seen by a mock server for the call above:
GET /repos/owner/repo/contents/docs/C%23/intro.md -> 404 (existence check, escaped)
PUT /repos/owner/repo/contents/docs/C (the write, unescaped)
I have a small fix with a regression test ready and can open a PR: escape each path segment before calling CreateFile, the same way escapeGitTreeish already does for tree lookups.
- 主要語言
- Go
- 星號
- 33.4k
- 分支
- 5.1k
- 平均合併
- 3 天 1 小時
- 30 天內合併 PR
- 35
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/github-mcp-server 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
github/github-mcp-server#3450 ·
維護者通常 4 天內回覆
-
request ai review
難度 2/5 1-3 小時 新手友好度 74/100
github/github-mcp-server#3439 ·
維護者通常 4 天內回覆
-
get_job_logs with failed_only misses failed jobs after the first 30 jobs of a run可能已有人在做 @jayhemnani9910 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
github/github-mcp-server#3428 ·
維護者通常 4 天內回覆
-
pull_request_read drops merge_commit_sha可能已有人在做 @thejdubb02 於 32 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 84/100
github/github-mcp-server#3235 · 1 則留言 ·
維護者通常 4 天內回覆
-
Add guidance on GitHub autolinked reference formatting for AI agents可能重新可做 關聯的 PR 已關閉且未合併。 未關閉enhancement
難度 1/5 1 小時以內 新手友好度 88/100
github/github-mcp-server#3042 · 2 則留言 ·
維護者通常 4 天內回覆
查看 github/github-mcp-server 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 85/100
mvanhorn/cli-printing-press#4980 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
-
priority: p3 type: feat
難度 2/5 1-3 小時 新手友好度 62/100
googleapis/librarian#7775 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
OpenTollGate/tollgate-module-basic-go#833 ·
維護者通常 1 天內回覆
-
documentation
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆