[BUG] Text.right_crop with a negative amount corrupts text length
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 66/100
Direzione di ricerca
Inizia da Text.right_crop() e dai relativi test nel repository Rich; l’issue non indica alcun file o test, quindi individuali cercando right_crop. Verifica come devono essere gestiti i valori negativi e confronta il testo e la lunghezza memorizzata nella cache prima e dopo il taglio. Il lavoro è completato quando un valore negativo non può lasciare il testo e la relativa lunghezza o gli spans in uno stato incoerente, con un test di regressione che copra il comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- 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.
- Lingua principale
- Python
- Stelle
- 57.8k
- Fork
- 2.6k
- Merge medio
- 20m
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Textualize/rich#4269 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/rich#4268 ·
-
Needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/rich#4267 ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Textualize/rich#4265 ·
Tutte le issue di Textualize/rich
Issue simili
-
author-page correction move-papers
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
acl-org/acl-anthology#10978 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
PostgreSQL results table stores labels with single quotes, and a double quote in a label fails the writeForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HKUDS/CLI-Anything#652 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Dao-AILab/flash-attention#3191 ·
I maintainer di solito rispondono entro 4 giorni