From 9ec5d2969530a6b2c4da354444189416f0a767be Mon Sep 17 00:00:00 2001 From: Chimdumebi Nebolisa Date: Sun, 1 Feb 2026 06:00:26 -0600 Subject: [PATCH 1/2] style: format zwj cell_len regression test (refs #3947) --- tests/test_zwj_cell_len.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/test_zwj_cell_len.py diff --git a/tests/test_zwj_cell_len.py b/tests/test_zwj_cell_len.py new file mode 100644 index 0000000000..3c40fabfa7 --- /dev/null +++ b/tests/test_zwj_cell_len.py @@ -0,0 +1,8 @@ +from rich.cells import cell_len + + +def test_cell_len_zwj_does_not_raise() -> None: + cell_len("\u200d") + cell_len("a\u200d") + cell_len("a\u200d\n b") + cell_len("a\u200d b(") From 43f2094d65f63d9bf92c413eda51123a47acfacf Mon Sep 17 00:00:00 2001 From: Chimdumebi Nebolisa Date: Sun, 1 Feb 2026 06:02:02 -0600 Subject: [PATCH 2/2] fix: avoid StopIteration on trailing zero-width joiner (refs #3947) --- rich/cells.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rich/cells.py b/rich/cells.py index 15fe7b65cd..8a03791ecd 100644 --- a/rich/cells.py +++ b/rich/cells.py @@ -140,7 +140,10 @@ def _cell_len(text: str, unicode_version: str) -> int: for character in iter_characters: if character in SPECIAL: if character == "\u200d": - next(iter_characters) + try: + next(iter_characters) + except StopIteration: + break elif last_measured_character: total_width += last_measured_character in cell_table.narrow_to_wide last_measured_character = None