[BUG] Segment.split_cells doesn't handle zero width charachters correctly
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
Start with Segment.split_cells and the cell-width helpers in rich/segment.py, then read split_text in rich/cells.py to see how it cuts text by cell position. Write a test like the one in the issue, using repr checks on the two halves of a Hebrew string with combining marks, and run it to see the current split. Done means the marks stay attached to their base characters and the existing cell-splitting tests still pass; the proposed split_text swap needs checking against them.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- I've checked docs and closed issues for possible solutions.
- I can't find my issue in the FAQ.
Describe the bug
Segment.split_cells() mishandles zero-width characters (such as Hebrew diacritical marks) when splitting text across cell boundaries, resulting in malformed segments where zero-width combining marks are incorrectly detached or split from their base characters.
Minimal reproduction / Unit Test
def test_split_cells_zero_width():
hebrew_segment = Segment("שָׁלוֹם")
left, right = hebrew_segment.split_cells(3)
assert repr(left) == "Segment('שָׁלוֹ')"
assert repr(right) == "Segment('ם')"
Proposed Fix
cells.py already has a function called split_text that can be used to solve the problem as such:
def _split_cells(cls, segment: "Segment", cut: int) -> tuple["Segment", "Segment"]:
"""Split a segment in to two at a given cell position.
Note that splitting a double-width character, may result in that character turning
into two spaces.
Args:
segment (Segment): A segment to split.
cut (int): A cell position to cut on.
Returns:
A tuple of two segments.
"""
text, style, control = segment
_Segment = Segment
cell_length = segment.cell_length
if cut >= cell_length:
return segment, _Segment("", style, control)
before, after = split_text(text, cut)
return (
_Segment(before, style, control),
_Segment(after, style, control),
)
I tried to publish it but wasn't able to since the repository limints pull requests t collaborators only.
- 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
-
HassSetVolumeRelative reports no targets (empty success list) although the volume was changedApertaintegration: media_player
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
home-assistant/core#193344 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
daniel-ospina/tortoise#13607 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation priority: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno