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

Aperta Adatta ai principianti
#16,130 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Il bug si trova in src/uu/nl/src/nl.rs, intorno alle righe 442-448, dove consecutive_empty_lines viene azzerato per ogni riga non vuota prima che venga eseguito il controllo del delimitatore di sezione. Prima compila con cargo build --locked -p uu_nl ed esegui la riproduzione dalla issue per confermare che l'output differisce da quello di GNU. È completato quando il conteggio delle righe vuote viene mantenuto attraverso il delimitatore, corrispondendo all'output atteso, e un caso di regressione è aggiunto ai test di nl.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
24.3k
Fork
2.1k
Merge medio
2g 6h
PR unite (30g)
399

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/coreutils

Tutte le issue di uutils/coreutils

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.