nl: section delimiters reset --join-blank-lines grouping

オープン 初心者向け
#16,130 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@coracoracora がすでに取り組んでいます。

2026年11月4日 から。

  • #16187 @coracoracora による — オープン

評価

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

調査の方向性

バグは src/uu/nl/src/nl.rs の442行目から448行目付近にあります。セクション区切りの判定が実行される前に、空でない行ごとに consecutive_empty_lines がリセットされています。まず cargo build --locked -p uu_nl でビルドし、issue の再現手順を実行して、出力が GNU と異なることを確認してください。区切り文字をまたいで空行の数が引き継がれ、期待される出力と一致し、nl のテストに回帰テストケースが追加されていれば完了です。

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

説明

U - nl

With -ba -l2, a section delimiter resets the count of blank lines in uutils. GNU preserves that count across the delimiter. This makes uutils omit a line number and shifts the numbering of subsequent text.

Reproduced on Linux x86_64 (Debian 13), with LC_ALL=C LANG=C, using uutils 0.13.0 built from current main at 43eb6205c20c551480057cdee98e6e7529cd984d. Compared with GNU coreutils 9.12 from the reference package linked in CONTRIBUTING.md; GNU 9.7 gives the same expected result.

Reproduction

From the repository root:

cargo build --locked -p uu_nl
export LC_ALL=C LANG=C
printf '%s\n' '' '\:\:' '' X | target/debug/nl -ba -l2 -w1 -s: | cat -A

The input is a blank line, a body-section delimiter, another blank line, and X. cat -A marks each line ending with $; the spaces below are literal.

Actual output:

  $
$
  $
1:X$

Expected output, produced by GNU 9.12 and 9.7 with the same arguments:

  $
$
1:$
2:X$

Both implementations exit 0 with empty stderr. GNU numbers the second blank line as 1 and the following text as 2; uutils leaves the blank line unnumbered and numbers the text as 1.

Adding -p also reproduces the difference, so this is separate from restarting line numbers at a section boundary. As controls, both implementations agree when the delimiter is removed, or replaced with ordinary text.

Cause

In nl.rs:442–448, consecutive_empty_lines is reset for every nonempty input line before checking whether the line is a section delimiter. The delimiter therefore clears the pending blank-line group.

No matching report was found in searches of open and closed issues and related PRs for nl, blank-line grouping, and section delimiters. #15586 concerns retaining the current section across input files; this reproduction uses a single input stream and still fails after that fix.

主要言語
Rust
スター
24.3k
フォーク
2.1k
平均マージ
2日 7時間
マージ済み PR(30日)
397

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

uutils/coreutils のほかの issue

uutils/coreutils の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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