summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-10-20 15:59:29 (GMT)
committerGitHub <noreply@github.com>2023-10-20 15:59:29 (GMT)
commitd731579bfb9a497cfb0076cb6b221058a20088fe (patch)
tree63eb8f9b8dfb7af9a5de6d4499ab375b80f208d4 /Doc
parent59ea0f523e155ac1a471cd292b41a76241fccd36 (diff)
downloadcpython-d731579bfb9a497cfb0076cb6b221058a20088fe.zip
cpython-d731579bfb9a497cfb0076cb6b221058a20088fe.tar.gz
cpython-d731579bfb9a497cfb0076cb6b221058a20088fe.tar.bz2
gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)
* PyUnicode_AsUTF8() now raises an exception if the string contains embedded null characters. * Update related C API tests (test_capi.test_unicode). * type_new_set_doc() uses PyUnicode_AsUTF8AndSize() to silently truncate doc containing null bytes. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/unicode.rst8
-rw-r--r--Doc/whatsnew/3.13.rst6
2 files changed, 14 insertions, 0 deletions
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
index 5ab9f1c..d17e63d 100644
--- a/Doc/c-api/unicode.rst
+++ b/Doc/c-api/unicode.rst
@@ -992,11 +992,19 @@ These are the UTF-8 codec APIs:
As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
+ Raise an exception if the *unicode* string contains embedded null
+ characters. To accept embedded null characters and truncate on purpose
+ at the first null byte, ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be
+ used instead.
+
.. versionadded:: 3.3
.. versionchanged:: 3.7
The return type is now ``const char *`` rather of ``char *``.
+ .. versionchanged:: 3.13
+ Raise an exception if the string contains embedded null characters.
+
UTF-32 Codecs
"""""""""""""
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index 804c7a8..34e4d67 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -1109,6 +1109,12 @@ Porting to Python 3.13
are now undefined by ``<Python.h>``.
(Contributed by Victor Stinner in :gh:`85283`.)
+* The :c:func:`PyUnicode_AsUTF8` function now raises an exception if the string
+ contains embedded null characters. To accept embedded null characters and
+ truncate on purpose at the first null byte,
+ ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be used instead.
+ (Contributed by Victor Stinner in :gh:`111089`.)
+
Deprecated
----------