Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#3,427 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

@jayhemnani9910 ci sta già lavorando.

Dal 6/10/2026.

  • #3429 di @jayhemnani9910 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
api

Direzione di ricerca

Inizia in pkg/github/repositories.go in CreateOrUpdateFile (v1.14.0 / 71ef8266), dove la chiamata CreateFile passa path non escapeato, e leggi escapeGitTreeish come schema esistente per l'escape per segmento. Confronta con i controlli di esistenza e symlink basati su GetContents, che già fanno l'escape correttamente. Il risultato assomiglia a PUT /repos/{owner}/{repo}/contents/docs/C%23/intro.md su un server mock, più un test di regression (estendi il file di test repositories esistente) che verifichi che i percorsi # e ? vengano scritti nel file giusto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
33.6k
Fork
5.2k
Merge medio
2g 15h
PR unite (30g)
37

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/github-mcp-server

Tutte le issue di github/github-mcp-server

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.