aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-26 08:34:41 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-26 10:13:41 +0200
commitf2b4abb43eec6427a42bd83ea2e54d7a40212260 (patch)
tree8f204f731a9de5eae3a27a84c4b684d7bf6d9a05
parenta3e882b06eda8f9a63cf3834a99640034775269b (diff)
PySide6: Allow for embedded 0 chars in 1 byte strings
Pass the length to QString::fromLatin1(). Amends b90acad7ebd389b34465504d229552af6c8196e5. Pick-to: 6.3 6.2 5.15 Fixes: PYSIDE-1895 Task-number: PYSIDE-1882 Change-Id: Ie829e479ad4e81f691cd3564ce1640175d1cdc32 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp2
-rw-r--r--sources/pyside6/tests/QtCore/qstring_test.py4
2 files changed, 5 insertions, 1 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index 5d358800c..916ef4ba4 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -1278,7 +1278,7 @@ void *data = _PepUnicode_DATA(%in);
Py_ssize_t len = PyUnicode_GetLength(%in);
switch (_PepUnicode_KIND(%in)) {
case PepUnicode_1BYTE_KIND:
- %out = QString::fromLatin1(reinterpret_cast<const char *>(data));
+ %out = QString::fromLatin1(reinterpret_cast<const char *>(data), len);
break;
case PepUnicode_2BYTE_KIND:
%out = QString::fromUtf16(reinterpret_cast<const char16_t *>(data), len);
diff --git a/sources/pyside6/tests/QtCore/qstring_test.py b/sources/pyside6/tests/QtCore/qstring_test.py
index a43b2b94a..b694b4fef 100644
--- a/sources/pyside6/tests/QtCore/qstring_test.py
+++ b/sources/pyside6/tests/QtCore/qstring_test.py
@@ -52,6 +52,10 @@ class QStringConstructor(unittest.TestCase):
self.assertEqual(obj.objectName(), 'foo')
obj.setObjectName('áâãà')
self.assertEqual(obj.objectName(), 'áâãà')
+ obj.setObjectName('A\x00B')
+ self.assertEqual(obj.objectName(), 'A\x00B')
+ obj.setObjectName('ä\x00B')
+ self.assertEqual(obj.objectName(), 'ä\x00B')
obj.setObjectName(None)
self.assertEqual(obj.objectName(), '')