Skip to content

Commit dc6f5ef

Browse files
committed
Copy potential BOM to the output of PyString_FromString
The documentation of the used `PyUnicode_DecodeUTF16` states that not passing `*byteorder` or passing a 0 results in the first two bytes, if they are the BOM (U+FEFF, zero-width no-break space), to be interpreted and skipped, which is incorrect when we convert a known "non BOM" string, which all strings from C# are.
1 parent 4c46c6d commit dc6f5ef

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/runtime/Runtime.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,14 @@ internal static bool PyString_CheckExact(BorrowedReference ob)
12521252

12531253
internal static NewReference PyString_FromString(string value)
12541254
{
1255+
int byteorder = BitConverter.IsLittleEndian ? -1 : 1;
1256+
int* byteorderPtr = &byteorder;
12551257
fixed(char* ptr = value)
12561258
return Delegates.PyUnicode_DecodeUTF16(
12571259
(IntPtr)ptr,
12581260
value.Length * sizeof(Char),
12591261
IntPtr.Zero,
1260-
IntPtr.Zero
1262+
(IntPtr)byteorderPtr
12611263
);
12621264
}
12631265

0 commit comments

Comments
 (0)