Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#3,427 コメント 0 件 リアクション 0 件 担当者 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 チェックと比較する。完成形は、モックサーバー上で 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時間
マージ済み PR(30日)
35

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/github-mcp-server のほかの issue

github/github-mcp-server の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。