mirror of
https://github.com/python/cpython.git
synced 2025-09-17 22:20:23 +00:00
fix escape_encode to return the correct consumed size
This commit is contained in:
parent
dd194ab37b
commit
034b0acdd3
2 changed files with 8 additions and 4 deletions
|
@ -835,6 +835,9 @@ class UnicodeInternalTest(unittest.TestCase):
|
||||||
self.assertEquals(encoder(u"a")[1], 1)
|
self.assertEquals(encoder(u"a")[1], 1)
|
||||||
self.assertEquals(encoder(u"\xe9\u0142")[1], 2)
|
self.assertEquals(encoder(u"\xe9\u0142")[1], 2)
|
||||||
|
|
||||||
|
encoder = codecs.getencoder("string-escape")
|
||||||
|
self.assertEquals(encoder(r'\x00')[1], 4)
|
||||||
|
|
||||||
# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
|
# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
|
||||||
nameprep_tests = [
|
nameprep_tests = [
|
||||||
# 3.1 Map to nothing.
|
# 3.1 Map to nothing.
|
||||||
|
|
|
@ -179,12 +179,13 @@ escape_encode(PyObject *self,
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
char *buf;
|
char *buf;
|
||||||
Py_ssize_t len;
|
Py_ssize_t consumed, len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
|
if (!PyArg_ParseTuple(args, "S|z:escape_encode",
|
||||||
&PyString_Type, &str, &errors))
|
&str, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
consumed = PyString_GET_SIZE(str);
|
||||||
str = PyString_Repr(str, 0);
|
str = PyString_Repr(str, 0);
|
||||||
if (!str)
|
if (!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -196,7 +197,7 @@ escape_encode(PyObject *self,
|
||||||
if (_PyString_Resize(&str, len-2) < 0)
|
if (_PyString_Resize(&str, len-2) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return codec_tuple(str, PyString_Size(str));
|
return codec_tuple(str, consumed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue