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

Cerrado Apto para principiantes
#16,120 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #16159 de @huuan26 — fusionado

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
cli

Línea de trabajo

El error está en src/uu/unexpand/src/unexpand.rs, en unexpand_buf cerca de la línea 583, donde el bucle copia el resto del búfer tal cual y termina cuando col alcanza lastcol, por lo que nunca se llega al manejo de backspace. Empieza ejecutando la reproducción del issue (printf 'abcde\b\b X\n' | target/debug/unexpand -t 3,5) y compara con la salida de GNU. Está terminado cuando los dos espacios se convierten en un tabulador (09) y se añade una prueba de regresión junto a las pruebas existentes de unexpand en tests/by-util/.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
24.3k
Forks
2.1k
Merge medio
2 d 7 h
PR fusionados (30 d)
397

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de uutils/coreutils

Todos los issues de uutils/coreutils

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.