mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-81548: Deprecate octal escape sequences with value larger than 0o377 (GH-91668)
This commit is contained in:
parent
a055dac0b4
commit
3483299a24
8 changed files with 139 additions and 18 deletions
|
@ -6404,6 +6404,12 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
|
|||
ch = (ch<<3) + *s++ - '0';
|
||||
}
|
||||
}
|
||||
if (ch > 0377) {
|
||||
if (*first_invalid_escape == NULL) {
|
||||
*first_invalid_escape = s-3; /* Back up 3 chars, since we've
|
||||
already incremented s. */
|
||||
}
|
||||
}
|
||||
WRITE_CHAR(ch);
|
||||
continue;
|
||||
|
||||
|
@ -6554,11 +6560,24 @@ _PyUnicode_DecodeUnicodeEscapeStateful(const char *s,
|
|||
if (result == NULL)
|
||||
return NULL;
|
||||
if (first_invalid_escape != NULL) {
|
||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||
"invalid escape sequence '\\%c'",
|
||||
(unsigned char)*first_invalid_escape) < 0) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
unsigned char c = *first_invalid_escape;
|
||||
if ('4' <= c && c <= '7') {
|
||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||
"invalid octal escape sequence '\\%.3s'",
|
||||
first_invalid_escape) < 0)
|
||||
{
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||
"invalid escape sequence '\\%c'",
|
||||
c) < 0)
|
||||
{
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue