Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e6dba0

Browse files
yihong0618grayjk
andauthored
gh-139246: zero-width word paste can be wrong in default repl (GH-139254)
Signed-off-by: yihong0618 <zouzou0208@gmail.com>Co-authored-by: grayjk <grayjk@gmail.com>
1 parenta3ce2f7 commit4e6dba0

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

‎Lib/_pyrepl/utils.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class ColorSpan(NamedTuple):
6363
defstr_width(c:str)->int:
6464
iford(c)<128:
6565
return1
66+
# gh-139246 for zero-width joiner and combining characters
67+
ifunicodedata.combining(c):
68+
return0
69+
category=unicodedata.category(c)
70+
ifcategory=="Cf"andc!="\u00ad":
71+
return0
6672
w=unicodedata.east_asian_width(c)
6773
ifwin ("N","Na","H","A"):
6874
return1

‎Lib/test/test_pyrepl/test_utils.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,29 @@
55

66
classTestUtils(TestCase):
77
deftest_str_width(self):
8-
characters= ['a','1','_','!','\x1a','\u263A','\uffb9']
8+
characters= [
9+
'a',
10+
'1',
11+
'_',
12+
'!',
13+
'\x1a',
14+
'\u263A',
15+
'\uffb9',
16+
'\N{LATIN SMALL LETTER E WITH ACUTE}',# é
17+
'\N{LATIN SMALL LETTER E WITH CEDILLA}',# ȩ
18+
'\u00ad',
19+
]
920
forcincharacters:
1021
self.assertEqual(str_width(c),1)
1122

23+
zero_width_characters= [
24+
'\N{COMBINING ACUTE ACCENT}',
25+
'\N{ZERO WIDTH JOINER}',
26+
]
27+
forcinzero_width_characters:
28+
withself.subTest(character=c):
29+
self.assertEqual(str_width(c),0)
30+
1231
characters= [chr(99989),chr(99999)]
1332
forcincharacters:
1433
self.assertEqual(str_width(c),2)
@@ -25,6 +44,8 @@ def test_wlen(self):
2544

2645
self.assertEqual(wlen('hello'),5)
2746
self.assertEqual(wlen('hello'+'\x1a'),7)
47+
self.assertEqual(wlen('e\N{COMBINING ACUTE ACCENT}'),1)
48+
self.assertEqual(wlen('a\N{ZERO WIDTH JOINER}b'),2)
2849

2950
deftest_prev_next_window(self):
3051
defgen_normal():
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: paste zero-width in default repl width is wrong.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp