GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pasting zero-width characters into PyREPL results in incorrect cursor position · Issue #139246 · python/cpython

Pasting zero-width characters into PyREPL results in incorrect cursor position #139246

New issue
Copy link
New issue
Copy link
Open
Open
Pasting zero-width characters into PyREPL results in incorrect cursor position#139246
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@grayjk
grayjk
opened on Sep 22, 2025
Issue body actions

Bug report

Bug description:

To reproduce

Tested with Python 3.14 rc3 on Linux

  1. Open the new REPL
  2. Paste: ééééé

The paste-able string above is five letter 'e's each followed by \u0301. To create it use:

print('e\u0301' * 5)

The \u0301 is a combining mark with zero-width display length

Current behavior

The cursor position is five spaces after the pasted string

Expected behavior

The cursor position is immediately after the pasted string

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

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

Activity

  1. grayjk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 22, 2025
  2. grayjk commented on Sep 22, 2025

    @grayjk
    grayjk
    on Sep 22, 2025
    ContributorAuthor
    More actions

    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 1

  3. StanFromIreland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shellRelated to the interactive shell
    on Sep 22, 2025
  4. StanFromIreland commented on Sep 22, 2025

    @StanFromIreland
    StanFromIreland
    on Sep 22, 2025
    Member
    More actions

    Possibly related: #130273

    >>> ééééé/0
    Traceback (most recent call last):
      File "<python-input-6>", line 1, in <module>
        ééééé/0
        ~~~~~~~~~~^~
    ZeroDivisionError: division by zero
    Reacted by grayjk
  5. grayjk commented on Sep 22, 2025

    @grayjk
    grayjk
    on Sep 22, 2025
    ContributorAuthor
    More actions

    @StanFromIreland It does look like traceback has a similar mishandling of zero-width characters in _display_width

  6. yihong0618 commented on Sep 23, 2025

    @yihong0618
    yihong0618
    on Sep 23, 2025
    Contributor
    More actions

    something like
    seems width is wrong here

    é
    ȩ
    
  7. yihong0618 commented on Sep 23, 2025

    @yihong0618
    yihong0618
    on Sep 23, 2025
    Contributor
    More actions

    I create a draft patch maybe can fix this can you help test?
    cc @grayjk

  8. grayjk commented on Sep 24, 2025

    @grayjk
    grayjk
    on Sep 24, 2025
    ContributorAuthor
    More actions

    Also affects Python 3.13

  9. encukou
    added a commit that references this issue on Oct 30, 2025

    gh-139246: zero-width word paste can be wrong in default repl (GH-139254

    4e6dba0
  10. miss-islington
    added a commit that references this issue on Oct 30, 2025

    pythongh-139246: zero-width word paste can be wrong in default repl (p…

    1d1a971
  11. StanFromIreland
    added a commit that references this issue on Nov 6, 2025

    [3.13] pythongh-139246: zero-width word paste can be wrong in default…

    1a8b6b5
  12. encukou
    added 2 commits that reference this issue on Nov 7, 2025

    [3.14] gh-139246: zero-width word paste can be wrong in default repl (G…

    d729087

    [3.13] gh-139246: zero-width word paste can be wrong in default repl (G…

    0923704
  13. encukou commented on Nov 7, 2025

    @encukou
    encukou
    on Nov 7, 2025
    Member
    More actions

    Thank you for the fix!
    Should we keep this open for consolidating this and the calculations for tracebacks?

  14. yihong0618 commented on Nov 7, 2025

    @yihong0618
    yihong0618
    on Nov 7, 2025
    Contributor
    More actions

    Thank you for the fix! Should we keep this open for consolidating this and the calculations for tracebacks?

    yes I think keep it open is better since there's a lot of case for the wcwidth

  15. grayjk commented on Dec 1, 2025

    @grayjk
    grayjk
    on Dec 1, 2025
    ContributorAuthor
    More actions

    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:

    print("\u1100\u1161")

    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

  16. yihong0618 commented on Dec 3, 2025

    @yihong0618
    yihong0618
    on Dec 3, 2025
    Contributor
    More actions

    가

    This is the same behavior in basic repl and other repl I think its fine here?

  17. typenoob commented on Dec 3, 2025

    @typenoob
    typenoob
    on Dec 3, 2025
    More actions

    가

    Image

    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.

  18. typenoob commented on Dec 3, 2025

    @typenoob
    typenoob
    on Dec 3, 2025
    More actions

    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

  19. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythongh-139246: zero-width word paste can be wrong in default repl (p…

    7281913
  20. StanFromIreland commented on May 9, 2026

    @StanFromIreland
    StanFromIreland
    on May 9, 2026 · Hidden as outdated
    show commentMore actions
  21. StanFromIreland
    closed this as a duplicateof Traceback colors are shifted when the line contains wide unicode characters #130273 on May 9, 2026
  22. StanFromIreland commented on May 9, 2026

    @StanFromIreland
    StanFromIreland
    on May 9, 2026 · Hidden as resolved
    show commentMore actions
  23. StanFromIreland
    reopened this on May 9, 2026
  24. StanFromIreland commented on May 9, 2026

    @StanFromIreland
    StanFromIreland
    on May 9, 2026
    Member
    More actions

    We get an incorrect number of carets for 가, and when trying delete it, on the second backspace it takes too much:

    >>> 가/0
    Traceback (most recent call last):
      File "<python-input-4>", line 1, in <module>
        가/0
        ^^^
    NameError: name '가' is not defined
    

    And, when trying delete it, on the second backspace it takes too much:

    >>
    
  25. grayjk commented on May 11, 2026

    @grayjk
    grayjk
    on May 11, 2026
    ContributorAuthor
    More actions

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.