Skip to content

Commit 07aa4bc

Browse files
committed
fix: address comments
Signed-off-by: yihong0618 <[email protected]>
1 parent 30e130f commit 07aa4bc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Lib/_pyrepl/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ def str_width(c: str) -> int:
6464
if ord(c) < 128:
6565
return 1
6666
# gh-139246 for zero-width joiner and combining characters
67-
if unicodedata.combining(c) or unicodedata.category(c) == "Cf":
67+
category = unicodedata.category(c)
68+
if unicodedata.combining(c):
69+
return 0
70+
if category == "Cf" and c != "\u00ad":
71+
return 0
72+
if "\u2028" <= c <= "\u2029":
6873
return 0
6974
w = unicodedata.east_asian_width(c)
7075
if w in ("N", "Na", "H", "A"):

Lib/test/test_pyrepl/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ def test_str_width(self):
1515
'\uffb9',
1616
'\N{LATIN SMALL LETTER E WITH ACUTE}', # é
1717
'\N{LATIN SMALL LETTER E WITH CEDILLA}', # ȩ
18+
'\u00ad',
1819
]
1920
for c in characters:
2021
self.assertEqual(str_width(c), 1)
2122

2223
zero_width_characters = [
2324
'\N{COMBINING ACUTE ACCENT}',
2425
'\N{ZERO WIDTH JOINER}',
26+
'\u2028',
27+
'\u2029',
2528
]
2629
for c in zero_width_characters:
2730
with self.subTest(character=c):

0 commit comments

Comments
 (0)