[BUG] Segment.split_cells doesn't handle zero width charachters correctly
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- 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.
- Ngôn ngữ chính
- Python
- Star
- 57.8k
- Fork
- 2.6k
- Merge trung bình
- 20 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Textualize/rich#4269 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Textualize/rich#4268 ·
-
Needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Textualize/rich#4267 ·
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Textualize/rich#4265 ·
Tất cả issue của Textualize/rich
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mohanraj00/entelos#200 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dead url in mise.tomlĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
sweep
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
bketelsen/truenas-mcp#77 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
sandbox-quantum/switch#2163 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
openedx/xblock-lti-consumer#765 ·
Maintainer thường phản hồi trong vòng 1 ngày