Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

create_or_update_file writes to the wrong file when the path contains # or ?

未关闭 适合新手
#3,427 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@jayhemnani9910 已经在做这个了。

开始于 2026年10月6日。

  • #3429 来自 @jayhemnani9910 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
api

调研方向

从 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
  1. Call create_or_update_file on a test repository:
    {"owner":"<you>","repo":"<test repo>","path":"docs/C#/intro.md","content":"# Intro","message":"Add intro","branch":"main"}
    
  2. 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/github-mcp-server 的其他 Issue

查看 github/github-mcp-server 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。