Skip to content

curses cell text is silently truncated at an embedded NUL #155877

Description

@fedonman

Bug description:

curses.complexchar() keeps only the text before an embedded NUL, so complexchar('a\0\u0301') silently drops the combining acute, and complexchar('\0') builds a cell with no text at all, whose repr() is not a valid constructor call.

import curses

print(repr(curses.complexchar('a\0\u0301')))
print(repr(curses.complexchar('a\u0301')))
r = repr(curses.complexchar('\0'))
print(r)
eval(r, {'curses': curses})
curses.complexchar('a')
curses.complexchar('á')
curses.complexchar('')
Traceback (most recent call last):
  File "/tmp/bug.py", line 7, in <module>
    eval(r, {'curses': curses})
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
TypeError: expect a string of 1 to 5 characters, got a str of length 0

The empty cell is worse than the truncation: window.addstr(curses.complexstr([curses.complexchar('\0'), curses.complexchar('B')])) returns None having written nothing. The same text reaches the same converter through window.addch(), insch(), echochar(), hline(), vline(), bkgd(), bkgdset(), border() and box(), and curses.complexstr('a\0b') drops the NUL and returns two cells.

Expected: ValueError: embedded null character, which window.addstr('a\0b') already raises.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions