Details
Description
Hi.
QPlainTextEdit.setPlainText raises ValueError if the input Unicode string contains non-terminator NULL characters. Although C definition of a string is a sequence of characters terminated by a NULL byte, this is Python and a pythonic string could contain any characters (including NULL character).
QPlainTextEdit().setPlainText("A\x00B")
Stack-trace:
Traceback (most recent call last):
File "/tmp/reproduce.py", line 28, in <module>
window = Window()
File "/tmp/reproduce.py", line 20, in _init_
self.txtbox.setPlainText("A\x00B") # A(0x41), NUL(0x00), B(0x42)
ValueError: embedded null character
It's notable that copy-pasting a string containing NULL characters to a QPlainTextEdit works properly and there is no problem on PySide6 (PySide2 was buggy). QPlainTextEdit.toPlainText() returns the pasted text containing NULL bytes properly without truncation or raising an exception.
Interestingly, as I observed, QPlainTextEdit.setPlainText() works properly on PyQT5 and PyQT6 and does not raise an exception or truncate the string up the first NULL character.
Please check out the attached Python script to reproduce the issue.
Attachments
Issue Links
- relates to
-
PYSIDE-1895 QPlainTextEdit.setPlainText() truncates the passed Unicode string up to the first embedded NULL character
- Closed
For Gerrit Dashboard: PYSIDE-1882 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
407472,2 | PySide6: Allow for embedded 0 chars in 1 byte strings | 6.3 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
407473,2 | PySide6: Allow for embedded 0 chars in 1 byte strings | 6.2 | pyside/pyside-setup | Status: ABANDONED | -1 | 0 |
407476,1 | PySide6: Allow for embedded 0 chars in 1 byte strings | tqtc/lts-5.15 | pyside/tqtc-pyside-setup | Status: ABANDONED | 0 | 0 |
407504,2 | PySide6: Allow for embedded 0 chars in 1 byte strings | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |