Skip to content

Commit a83a6a3

Browse files
Issue #28701: _PyUnicode_EqualToASCIIId and _PyUnicode_EqualToASCIIString now
require ASCII right argument and assert this condition in debug build.
1 parent ecbca35 commit a83a6a3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Include/unicodeobject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ PyAPI_FUNC(int) PyUnicode_Compare(
20382038

20392039
#ifndef Py_LIMITED_API
20402040
/* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
2041-
0 otherwise. Return 0 if any argument contains non-ASCII characters.
2041+
0 otherwise. The right argument must be ASCII identifier.
20422042
Any error occurs inside will be cleared before return. */
20432043

20442044
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
@@ -2060,7 +2060,7 @@ PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString(
20602060

20612061
#ifndef Py_LIMITED_API
20622062
/* Test whether a unicode is equal to ASCII string. Return 1 if true,
2063-
0 otherwise. Return 0 if any argument contains non-ASCII characters.
2063+
0 otherwise. The right argument must be ASCII-encoded string.
20642064
Any error occurs inside will be cleared before return. */
20652065

20662066
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString(

Objects/unicodeobject.c

+11
Original file line numberDiff line numberDiff line change
@@ -11081,6 +11081,12 @@ _PyUnicode_EqualToASCIIString(PyObject *unicode, const char *str)
1108111081
{
1108211082
size_t len;
1108311083
assert(_PyUnicode_CHECK(unicode));
11084+
assert(str);
11085+
#ifndef NDEBUG
11086+
for (const char *p = str; *p; p++) {
11087+
assert((unsigned char)*p < 128);
11088+
}
11089+
#endif
1108411090
if (PyUnicode_READY(unicode) == -1) {
1108511091
/* Memory error or bad data */
1108611092
PyErr_Clear();
@@ -11101,6 +11107,11 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
1110111107

1110211108
assert(_PyUnicode_CHECK(left));
1110311109
assert(right->string);
11110+
#ifndef NDEBUG
11111+
for (const char *p = right->string; *p; p++) {
11112+
assert((unsigned char)*p < 128);
11113+
}
11114+
#endif
1110411115

1110511116
if (PyUnicode_READY(left) == -1) {
1110611117
/* memory error or bad data */

0 commit comments

Comments
 (0)