Skip to content

Commit e3410ed

Browse files
committed
fix(string): fix utf16 strings that contain surrogate pairs
1 parent adb18fb commit e3410ed

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/StrType.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ PyObject *StrType::proxifyString(JSContext *cx, JS::HandleValue strVal) {
165165
}
166166
else { // utf16 spidermonkey, ucs2 python
167167
const char16_t *chars = JS::GetTwoByteLinearStringChars(nogc, lstr);
168-
if ((PY_VERSION_HEX) >= 0x030d0000) { // Python 3.13+, see above
169-
PyObject *copied = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, chars, length);
170-
Py_DECREF(pyString);
171-
return copied;
172-
}
173168

174169
PY_UNICODE_OBJECT_DATA_ANY(pyString) = (void *)chars;
175170
PY_UNICODE_OBJECT_KIND(pyString) = PyUnicode_2BYTE_KIND;
@@ -202,6 +197,11 @@ PyObject *StrType::proxifyString(JSContext *cx, JS::HandleValue strVal) {
202197
Py_DECREF(pyString);
203198
return ucs4Obj;
204199
}
200+
if ((PY_VERSION_HEX) >= 0x030d0000) { // Python 3.13+, fix `ValueError: embedded null character`
201+
PyObject *copied = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, chars, length); // create a copy of the string buffer
202+
Py_DECREF(pyString);
203+
return copied;
204+
}
205205
}
206206

207207
return (PyObject *)pyString;

0 commit comments

Comments
 (0)