Skip to content
9 changes: 9 additions & 0 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,15 @@ These are the UTF-8 codec APIs:

As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.

.. warning::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A warning is a strong signal. Maybe a note is enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had it as a note, but I think a warning is what we want here. I only discovered this quirk of PyUnicode_AsUTF8 because it caused a crash in the _interpreters module. Things that can potentially cause security issues should probably get a warning, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that notes about security are usually documented in red as warnings.


This function does not have any special behavior for
`null bytes <https://en.wikipedia.org/wiki/Null_character>`_ embedded within
*unicode*. As a result, strings containing null bytes will remain in the returned
string, which some C functions might interpret as the end of the string, leading to
truncation. When handling user input, it is recommended to use :c:func:`PyUnicode_AsUTF8AndSize`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that "user input" is useful here. I would prefer to say something like: "If truncation is an issue, ..."

instead.

.. versionadded:: 3.3

.. versionchanged:: 3.7
Expand Down
Loading