mirror of https://github.com/python/cpython
bpo-31825: Fixed OverflowError in the 'unicode-escape' codec (#4058)
and in codecs.escape_decode() when decode an escaped non-ascii byte.
This commit is contained in:
parent
525f40d231
commit
56cb465cc9
|
@ -1203,6 +1203,8 @@ class EscapeDecodeTest(unittest.TestCase):
|
|||
check(br"\8", b"\\8")
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
check(br"\9", b"\\9")
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
check(b"\\\xfa", b"\\\xfa")
|
||||
|
||||
def test_errors(self):
|
||||
decode = codecs.escape_decode
|
||||
|
@ -2474,6 +2476,8 @@ class UnicodeEscapeTest(unittest.TestCase):
|
|||
check(br"\8", "\\8")
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
check(br"\9", "\\9")
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
check(b"\\\xfa", "\\\xfa")
|
||||
|
||||
def test_decode_errors(self):
|
||||
decode = codecs.unicode_escape_decode
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fixed OverflowError in the 'unicode-escape' codec and in
|
||||
codecs.escape_decode() when decode an escaped non-ascii byte.
|
|
@ -1257,7 +1257,7 @@ PyObject *PyBytes_DecodeEscape(const char *s,
|
|||
if (first_invalid_escape != NULL) {
|
||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||
"invalid escape sequence '\\%c'",
|
||||
*first_invalid_escape) < 0) {
|
||||
(unsigned char)*first_invalid_escape) < 0) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -6136,7 +6136,7 @@ PyUnicode_DecodeUnicodeEscape(const char *s,
|
|||
if (first_invalid_escape != NULL) {
|
||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||
"invalid escape sequence '\\%c'",
|
||||
*first_invalid_escape) < 0) {
|
||||
(unsigned char)*first_invalid_escape) < 0) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -4147,7 +4147,7 @@ decode_utf8(struct compiling *c, const char **sPtr, const char *end)
|
|||
|
||||
static int
|
||||
warn_invalid_escape_sequence(struct compiling *c, const node *n,
|
||||
char first_invalid_escape_char)
|
||||
unsigned char first_invalid_escape_char)
|
||||
{
|
||||
PyObject *msg = PyUnicode_FromFormat("invalid escape sequence \\%c",
|
||||
first_invalid_escape_char);
|
||||
|
|
Loading…
Reference in New Issue