You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pasting zero-width characters into PyREPL results in incorrect cursor position #139246
Activity
grayjk commentedon Sep 22, 2025
The root cause seems to be related to pyrepl wlen miscalculating the length of the zero-width combining mark
wlen('e\u0301')is 2 instead of 1StanFromIreland commentedon Sep 22, 2025
Possibly related: #130273
grayjk commentedon Sep 22, 2025
@StanFromIreland It does look like traceback has a similar mishandling of zero-width characters in _display_width
yihong0618 commentedon Sep 23, 2025
something like
seems width is wrong here
yihong0618 commentedon Sep 23, 2025
I create a draft patch maybe can fix this can you help test?
cc @grayjk
grayjk commentedon Sep 24, 2025
Also affects Python 3.13
gh-139246: zero-width word paste can be wrong in default repl (GH-139254
pythongh-139246: zero-width word paste can be wrong in default repl (p…
[3.13] pythongh-139246: zero-width word paste can be wrong in default…
[3.14] gh-139246: zero-width word paste can be wrong in default repl (G…
[3.13] gh-139246: zero-width word paste can be wrong in default repl (G…
encukou commentedon Nov 7, 2025
Thank you for the fix!
Should we keep this open for consolidating this and the calculations for tracebacks?
yihong0618 commentedon Nov 7, 2025
yes I think keep it open is better since there's a lot of case for the wcwidth
grayjk commentedon Dec 1, 2025
Hangul Jamo (https://www.unicode.org/faq/korean#3) also has zero width conjoining characters: https://wcwidth.readthedocs.io/en/latest/specs.html#width-of-0
An example is:
which displays:
가The pyrepl wlen function in 3.15.0a2 returns 3 for this character. The length should be 2
Since the wlen return is incorrect, pasting the character results in an incorrect cursor position
yihong0618 commentedon Dec 3, 2025
This is the same behavior in basic repl and other repl I think its fine here?
typenoob commentedon Dec 3, 2025
It somehow looks ugly in my 3.14.0 REPL. (I think it's the OS problem, it looks fine on Linux)
And yes, we should calc its wlen as 2.
typenoob commentedon Dec 3, 2025
Do you think we should improve wlen and str_width based on wcwidth, or we should only fix when there's incorrect behavior occurs? @grayjk
pythongh-139246: zero-width word paste can be wrong in default repl (p…
StanFromIreland commentedon May 9, 2026
StanFromIreland commentedon May 9, 2026
StanFromIreland commentedon May 9, 2026
We get an incorrect number of carets for
가, and when trying delete it, on the second backspace it takes too much:And, when trying delete it, on the second backspace it takes too much:
grayjk commentedon May 11, 2026
@StanFromIreland what Python version?
I tested in 3.15.0 beta 1 with Putty and it worked (i.e. displayed 2 carets).
The backspace problem is tracked in issue #142162