[3.13] gh-139246: zero-width word paste can be wrong in default repl (GH-139254) (GH-141166)

(cherry picked from commit 4e6dba0ef7)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: yihong <zouzou0208@gmail.com>
Co-authored-by: grayjk <grayjk@gmail.com>
This commit is contained in:
Stan Ulbrych 2025-11-07 12:51:03 +00:00 committed by GitHub
parent 353bfc813b
commit 0923704b49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View file

@ -14,6 +14,12 @@
def str_width(c: str) -> int:
if ord(c) < 128:
return 1
# gh-139246 for zero-width joiner and combining characters
if unicodedata.combining(c):
return 0
category = unicodedata.category(c)
if category == "Cf" and c != "\u00ad":
return 0
w = unicodedata.east_asian_width(c)
if w in ("N", "Na", "H", "A"):
return 1