Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
filmor committed May 5, 2024
commit dc6f5efb7905ff695d244a65e0afc161be6ef1af
4 changes: 3 additions & 1 deletion src/runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,12 +1252,14 @@ internal static bool PyString_CheckExact(BorrowedReference ob)

internal static NewReference PyString_FromString(string value)
{
int byteorder = BitConverter.IsLittleEndian ? -1 : 1;
int* byteorderPtr = &byteorder;
fixed(char* ptr = value)
return Delegates.PyUnicode_DecodeUTF16(
(IntPtr)ptr,
value.Length * sizeof(Char),
IntPtr.Zero,
IntPtr.Zero
(IntPtr)byteorderPtr
);
}

Expand Down