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

オープン
#203 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
bash, shell
領域
cli

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Shell
スター
3.3k
フォーク
2.7k
平均マージ
1時間 56分
マージ済み PR(30日)
21

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ekalinin/github-markdown-toc のほかの issue

ekalinin/github-markdown-toc の issue をすべて見る

似ている issue

Shell/Bash の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。