Skip to content

formatting character values >= 128 gives unexpected results #13084

@jepler

Description

@jepler
$ ./build-coverage/micropython
MicroPython 9c7067d9ad on 2023-11-28; linux [GCC 12.2.0] version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> s = f"{160:c}"
>>> len(s)
0
>>> s
' '
>>> print(s)
�

The same for s = "%c" % 160.

I think this is because the 'c' formatter in objstr.c doesn't handle non-ASCII characters properly. It looks like this ends up being another way to get improper UTF-8 into a str() object, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugunicodeBugs and enhancements related to Unicode/UTF-8 support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions