Skip to content

'str' to 'wxString' converstation is broken, when emoji is inside string #2446

@timrid

Description

@timrid

Operating system: Windows 10
wxPython version & source: wxPython 4.2.1 from pypi
Python version & source: Python 3.11

Description of the problem:
Whem some special emojis like 🔄 are inside a python string, that is converted to an wxString (internally in wxPython), the last character of the string is lost. It is also not shown in the gui.

The changes in 29520a1 creates the problem. I compiled it with and without the changes and only with the changes the error occures. I guess that PyUnicode_GET_LENGTH is not an 1:1 replacement for PyUnicode_GET_SIZE.

I created the following small example to illustrate the problem.

import wx

app = wx.App(False)
txt = wx.Button()

def test_string(input):
    txt.SetLabel(input)
    output = txt.GetLabel()
    print(f"{input=}, {output=}")

test_string("asdf")  # Output is: "asdf" -> ok
test_string("⟳ asdf")  # Output is: "⟳ asdf" -> ok
test_string("🔄 asdf")  # Output is: "🔄 asd" -> error: last char is missing
test_string("🔄🔄 asdf")  # Output is: "🔄🔄 as" -> error: last two chars are missing
test_string("🔄")  # Output is: "\ud83d" -> error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions