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 于 4 天前认领。 未关闭
难度 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 小时 新手友好度 75/100
prime-radiant-inc/evener#4223 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
open-telemetry/opentelemetry-go-compile-instrumentation#1467 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
modelcontextprotocol/go-sdk#1367 · 1 条评论 ·
维护者通常 1 天内回复