aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-26 08:34:41 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-04-26 11:38:30 +0000
commit5fea94774123ba2cec71e29a7c93dcd2edfb7ab5 (patch)
tree5619e0b925cc24737f32d1824f80d4e4a2448582 /sources/pyside6
parentd2cb517632862979749c0f525e64d0ee64597a3b (diff)
PySide6: Allow for embedded 0 chars in 1 byte strings
Pass the length to QString::fromLatin1(). Amends b90acad7ebd389b34465504d229552af6c8196e5. Fixes: PYSIDE-1895 Task-number: PYSIDE-1882 Change-Id: Ie829e479ad4e81f691cd3564ce1640175d1cdc32 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit f2b4abb43eec6427a42bd83ea2e54d7a40212260) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources/pyside6')
-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(), '')