[ BUG ] Backslash sequences in heading text are interpreted by echo -e

Aberta
#203 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
76/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
bash, shell
Domínio
cli

Direção de pesquisa

Start at gh_toc_grab around line 470, where the generated TOC passes through echo -e, and trace how the href escapes are produced by the awk script. Reproduce with the supplied headings containing \n and \c, then check that the generated TOC preserves those backslashes and retains later entries. Verify both normal output and --insert --no-backup --hide-footer.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug

Describe the bug

A backslash sequence in the heading text, such as \n or \c, is interpreted in the TOC entry. \n splits the entry into two lines, and \c cuts the TOC: the rest of that entry and all the entries after it are lost.

gh_toc_grab prints the TOC with echo -e (line 470 on master at a28f86d):

echo $echoargs "$(awk ... "$awkscript")"

-e is there for the link: awk turns every % of the href into \x, and echo -e decodes the \xNN sequences, see #6 and #10. But the whole line goes through it, so the heading text does too. The OS/390 branch sets echoargs="", so it is not affected.

To Reproduce

cat > test.md <<'MD'
# Top

## The `\n` escape

## Use \c to stop

## Last
MD
./gh-md-toc test.md

Output:

Table of Contents
=================

* [Top](#top)
   * [The 
 escape](#the-n-escape)
   * [Use 

<!-- Created by https://github.com/ekalinin/github-markdown-toc -->

GitHub renders these headings as The <code>\n</code> escape, Use \c to stop and Last, so the backslashes come into gh_toc_grab as they are.

--insert --no-backup --hide-footer writes the same broken TOC into the file, with exit code 0:

<!--ts-->
* [Top](#top)
   * [The 
 escape](#the-n-escape)
   * [Use 
<!--te-->

Expected behavior

* [Top](#top)
   * [The \n escape](#the-n-escape)
   * [Use \c to stop](#use-c-to-stop)
   * [Last](#last)

Environment (please complete the following information):

  • OS: macOS (Darwin 24.6.0), GNU bash 5.3.15
  • Version: 0.11.0 (master at a28f86d)

Additional context

Found while working on #153: headings with inline code, such as `\n`, are more likely to have a backslash. It is the same with and without --keep-code from #202.

Linguagem predominante
Shell
Estrelas
3.3k
Forks
2.7k
Merge médio
1h 56min
PRs com merge (30d)
21

Preparar o ambiente

  • Inclui um Dockerfile ou arquivo Docker Compose
  • Sem modelo de pull request
  • Sem guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de ekalinin/github-markdown-toc

Todas as issues de ekalinin/github-markdown-toc

Issues semelhantes

Mais issues de Shell/Bash

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.