[BUG] Text.right_crop with a negative amount corrupts text length
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 66/100
Línea de trabajo
Empieza por Text.right_crop() y sus pruebas en el repositorio Rich; el issue no indica ningún archivo ni prueba, así que localízalos buscando right_crop. Comprueba cómo deben tratarse las cantidades negativas y compara el texto y la longitud almacenada en caché antes y después de recortar. La tarea estará terminada cuando una cantidad negativa no pueda dejar el texto y su longitud o sus spans en un estado incoherente, y una prueba de regresión cubra ese comportamiento.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
- I've checked docs and searched open and closed issues for possible solutions.
- I can't find my issue in the FAQ.
Describe the bug
Text.right_crop() behaves unexpectedly for a negative amount: it removes characters from the start of the text while increasing the cached length, leaving the Text object internally inconsistent.
Minimal reproduction:
from rich.text import Text
text = Text(abc)
text.right_crop(-1)
print(repr(text.plain), len(text))
Observed output:
'a' 4
A value of -4 leaves plain == abc but reports len(text) == 7. The implementation calculates self.plain[:-amount] and subtracts amount from the cached length, so negative values both slice from the wrong end and increase the cached length. Subsequent operations that rely on the cached length or span offsets can then behave incorrectly.
Expected behavior: a negative crop amount should not silently mutate the text or invalidate its length/spans. Rejecting negative values with ValueError would make the invalid input explicit; please advise if a different contract is preferred.
This report and reproduction were prepared with GitHub Copilot assistance; the example was run locally against the current checkout.
Platform
Click to expand
Windows, PowerShell. The behavior is in Text's internal string/length bookkeeping and does not depend on terminal rendering.
- Lenguaje dominante
- Python
- Estrellas
- 57.8k
- Forks
- 2.6k
- Merge medio
- 20 min
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Textualize/rich#4269 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Textualize/rich#4268 ·
-
Needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Textualize/rich#4267 ·
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Textualize/rich#4265 ·
Todos los issues de Textualize/rich
Issues similares
-
Internal ErrorAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
frappe/frappe_docker#2071 ·
Los mantenedores suelen responder en 1 día
-
bug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Abiertocomp/desktop P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NousResearch/hermes-agent#157702 ·
Los mantenedores suelen responder en 1 día
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPosiblemente ocupada @BahaaMattar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Los mantenedores suelen responder en 1 día