[ BUG ] --insert writes LF line endings into a file with CRLF line endings

Abierto Apto para principiantes
#101 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Empieza por internal/core/usecase/insertmd/markers.go y sigue cómo replaceBetweenMarkers maneja los finales de línea; el issue también indica que la misma regla se aplica a --stdout (#95). Reproduce el problema con la entrada CRLF proporcionada y comprueba después que las líneas insertadas usan CRLF cuando la marca de inicio tiene un \r al final, mientras que las demás líneas permanecen sin cambios.

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

Descripción

bug

Describe the bug

In a file with CRLF line endings, --insert finds the markers, but every line it writes
between them ends with \n only, so the file ends up with mixed line endings. The Bash
version writes these lines with \r\n when the <!--ts--> line ends with \r
(ekalinin/github-markdown-toc#119, fixed in ekalinin/github-markdown-toc#195).

To Reproduce

printf '<!--ts-->\r\n<!--te-->\r\n\r\n# Title\r\n\r\n## Section\r\n' > crlf.md
gh-md-toc --insert --no-backup crlf.md
od -c crlf.md

Actual, line by line:

<!--ts-->\r\n
* [Title](#title)\n
  * [Section](#section)\n
\n
<!-- Created by https://github.com/ekalinin/github-markdown-toc.go -->\n
<!-- Added by: <user>, at: <date> -->\n
<!--te-->\r\n
\r\n
# Title\r\n
\r\n
## Section\r\n

Expected behavior

When the <!--ts--> line ends with \r, every line written between the markers (the TOC
entries, the empty line and the footer lines) ends with \r\n. Otherwise they end with
\n, as now. All other lines are kept as they are.

Environment (please complete the following information):

  • OS: macOS (darwin/arm64)
  • Version: 2.0.1, current master (dd680f7)

Additional context

  • replaceBetweenMarkers (internal/core/usecase/insertmd/markers.go) splits the file on
    \n and joins the TOC block with \n. The marker lines already keep their \r.
  • The same rule applies to --stdout (#95).
Lenguaje dominante
Go
Estrellas
525
Forks
89
Merge medio
6 min
PR fusionados (30 d)
1

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

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 ekalinin/github-markdown-toc.go

Todos los issues de ekalinin/github-markdown-toc.go

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.