[ BUG ] Backslash sequences in heading text are interpreted by echo -e
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 76/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Shell
- Étoiles
- 3.3k
- Forks
- 2.7k
- Merge moyen
- 1 h 56 min
- PR mergées (30 j)
- 21
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ekalinin/github-markdown-toc
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
ekalinin/github-markdown-toc#204 ·
Les mainteneurs répondent en général sous 1 jour
-
[ BUG ] Headings are missing from the TOC when GitHub puts a line break after the heading tagOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
ekalinin/github-markdown-toc#201 ·
Les mainteneurs répondent en général sous 1 jour
-
Update bats version in CIOuverteenhancement
Difficulté 1/5 1-3 heures Accessibilité débutants 78/100
ekalinin/github-markdown-toc#176 ·
Les mainteneurs répondent en général sous 1 jour
-
Update outdated examples and versions in READMEPeut-être pris @SatvikMishra08 l’a pris il y a 42 jours. Ouvertedocumentation
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
ekalinin/github-markdown-toc#165 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 3/5 1-2 jours Accessibilité débutants 70/100
ekalinin/github-markdown-toc#194 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de ekalinin/github-markdown-toc
Issues similaires
-
flac's CMake config is brokenOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
msys2/MINGW-packages#33356 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Misleading 'Update → Config → Hyprland' menu item silently resets user configs without confirmationOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
kunchenguid/headless#23 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
mack-a/v2ray-agent#1370 ·