@@ -135,9 +135,11 @@ PyObject *StrType::proxifyString(JSContext *cx, JS::HandleValue strVal) {
135
135
136
136
if (JS::LinearStringHasLatin1Chars (lstr)) { // latin1 spidermonkey, latin1 python
137
137
const JS::Latin1Char *chars = JS::GetLatin1LinearStringChars (nogc, lstr);
138
- if (chars[length] != 0 ) { // not a null-terminated string
139
- // most Python C APIs assume the string buffer is null-terminated, so we need to create a copy
140
- PyObject *copied = PyUnicode_FromObject (pyString); // create a copy when it's not a true Unicode object
138
+ if (Py_Version >= 0x030d0000 ) { // Python version is greater than 3.13
139
+ // Short path to temporarily fix the issue with Python 3.13+ compact unicode representation.
140
+ // It would error with `ValueError: embedded null character`, which is caused by the fact that
141
+ // most Python C APIs assume the string buffer is null-terminated, so we need to create a copy.
142
+ PyObject *copied = PyUnicode_FromObject ((PyObject *)pyString); // create a copy when it's not a true Unicode object
141
143
Py_DECREF (pyString);
142
144
return copied;
143
145
}
@@ -163,8 +165,8 @@ PyObject *StrType::proxifyString(JSContext *cx, JS::HandleValue strVal) {
163
165
}
164
166
else { // utf16 spidermonkey, ucs2 python
165
167
const char16_t *chars = JS::GetTwoByteLinearStringChars (nogc, lstr);
166
- if (chars[length] != 0 ) { // not a null-terminated string
167
- PyObject *copied = PyUnicode_FromObject (pyString);
168
+ if (Py_Version >= 0x030d0000 ) { // Python 3.13+, see above
169
+ PyObject *copied = PyUnicode_FromObject ((PyObject *) pyString); // create a copy when it's not a true Unicode object
168
170
Py_DECREF (pyString);
169
171
return copied;
170
172
}
0 commit comments