unexpand: backspaces before the last tab stop do not resume tab conversion

Aperta Adatta ai principianti
#16,120 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
78/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/unexpand/src/unexpand.rs, in unexpand_buf vicino alla riga 583, dove il ciclo copia il resto del buffer così com'è e termina quando col raggiunge lastcol, quindi la gestione del backspace non viene mai raggiunta. Inizia eseguendo la riproduzione dell'issue (printf 'abcde\b\b X\n' | target/debug/unexpand -t 3,5) e confronta con l'output di GNU. Il lavoro è completato quando i due spazi diventano una tabulazione (09) e un test di regressione è aggiunto accanto ai test esistenti di unexpand in tests/by-util/.

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

Descrizione

U - unexpand

With a finite tab-stop list, unexpand stops converting spaces once it reaches the last stop, even when subsequent backspaces move the column back before that stop.

Verified on Linux x86_64 (Debian 13), LC_ALL=C LANG=C, using uutils 0.13.0 built from main at 9cc868bcab387842ea2fa7b8e85c76e05860c51f. GNU coreutils 9.12 (the reference package linked in CONTRIBUTING.md) and 9.7 both produce the expected output.

Reproduction

From the repository root:

cargo build --locked -p uu_unexpand
export LC_ALL=C LANG=C
printf 'abcde\b\b  X\n' | target/debug/unexpand -t 3,5 | od -An -tx1

Actual bytes:

61 62 63 64 65 08 08 20 20 58 0a

Expected bytes (GNU 9.12 and 9.7):

61 62 63 64 65 08 08 09 58 0a

The two spaces (20 20) should become a tab (09). After abcde the column is 5; the two backspaces move it to 3, so the following two spaces reach the configured stop at 5. Both implementations exit 0 with empty stderr, but uutils leaves those spaces unconverted.

The same difference occurs without a trailing newline. As controls, both implementations agree when the tab list is 3,5,8, or when the initial text is abc instead of abcde. This isolates the failure to reaching the final configured stop before backspacing.

Cause

In unexpand.rs:583, unexpand_buf copies the remaining buffer verbatim and breaks as soon as col >= lastcol. That skips the backspace handling which would decrease the column and allow conversion again.

No matching report was found in searches of open and closed issues, relevant PRs, and discussions mentioning unexpand and backspaces.

Lingua principale
Rust
Stelle
24.3k
Fork
2.1k
Merge medio
1g 22h
PR unite (30g)
396

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.