From 1f79792ec824d1792f76c4ff6d47e32affab7c8a Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sat, 1 Oct 2022 20:27:11 +0200 Subject: Fix handling of UCS-2 encoded strings Add test to python/demo.py Fixes #2132 --- src/py_utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/py_utils.cc') diff --git a/src/py_utils.cc b/src/py_utils.cc index d1413fec..cd44aa93 100644 --- a/src/py_utils.cc +++ b/src/py_utils.cc @@ -140,7 +140,7 @@ struct string_from_python case PyUnicode_1BYTE_KIND: { Py_UCS1* value = PyUnicode_1BYTE_DATA(obj_ptr); if (value == 0) throw_error_already_set(); - str = std::string(value); + utf8::unchecked::utf16to8(value, value + size, std::back_inserter(str)); } break; #if PY_MINOR_VERSION < 12 && Py_UNICODE_SIZE == 2 case PyUnicode_WCHAR_KIND: -- cgit v1.2.3