Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1882

QPlainTextEdit.setPlainText raises ValueError if the Unicode string contains NULL characters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.3.0
    • 6.2.4
    • PySide
    • None
    • PySide version: 6.2.4
      Python versions: Python3.10, Python3.8
      Platform: Ubuntu 20.04
    • Linux/X11
    • b90acad7ebd389b34465504d229552af6c8196e5

    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

        1. pyside1882.py
          1 kB
        2. reproduce.py
          1 kB

        Issue Links

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              bulmaro.jerrick Bulmaro Jerrick
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: