[BUG] Segment.split_cells doesn't handle zero width charachters correctly
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 42/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
- 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.
- 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
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
sandbox-quantum/switch#2163 ·
Los mantenedores suelen responder en 1 día
-
bug pydanty:is-working
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
pydantic/pydantic-ai#13939 ·
Los mantenedores suelen responder en 1 día
-
priority: low python
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
LearningCircuit/local-deep-research#8849 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
francescopace/espectre#223 ·
Los mantenedores suelen responder en 3 días
-
good first issue Status: Triaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
canonical/imagecraft#538 · 1 comentario ·
Los mantenedores suelen responder en 2 días