Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#3,427 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

@jayhemnani9910 ya está trabajando en esto.

Desde el 6/10/2026.

  • #3429 de @jayhemnani9910 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
84/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
api

Línea de trabajo

Empieza en pkg/github/repositories.go en CreateOrUpdateFile (v1.14.0 / 71ef8266), donde la llamada a CreateFile pasa path sin escapar, y lee escapeGitTreeish como el patrón existente para el escapado por segmento. Compara con las comprobaciones de existencia y symlink basadas en GetContents, que ya escapan correctamente. El resultado se ve como PUT /repos/{owner}/{repo}/contents/docs/C%23/intro.md en un servidor simulado, más una prueba de regresión (amplía el archivo de pruebas de repositories existente) que verifique que las rutas # y ? se escriben en el archivo correcto.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
33.4k
Forks
5.1k
Merge medio
3 d 1 h
PR fusionados (30 d)
35

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/github-mcp-server

Todos los issues de github/github-mcp-server

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.