diff options
author | Philip Jenvey <pjenvey@underboss.org> | 2010-04-05 02:51:51 (GMT) |
---|---|---|
committer | Philip Jenvey <pjenvey@underboss.org> | 2010-04-05 02:51:51 (GMT) |
commit | 034b0acdd35cc5b5fb059dc635cc39a234ed5d07 (patch) | |
tree | 190d284ba58d8d40813410d0bb70cd6c0556fb5b | |
parent | dd194ab37b07a6f01da7d2981e5c2a504c6bdf98 (diff) | |
download | cpython-034b0acdd35cc5b5fb059dc635cc39a234ed5d07.zip cpython-034b0acdd35cc5b5fb059dc635cc39a234ed5d07.tar.gz cpython-034b0acdd35cc5b5fb059dc635cc39a234ed5d07.tar.bz2 |
fix escape_encode to return the correct consumed size
-rw-r--r-- | Lib/test/test_codecs.py | 3 | ||||
-rw-r--r-- | Modules/_codecsmodule.c | 9 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 8caf018..f8563f6 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -835,6 +835,9 @@ class UnicodeInternalTest(unittest.TestCase): self.assertEquals(encoder(u"a")[1], 1) 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 nameprep_tests = [ # 3.1 Map to nothing. diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index 495e4ff..c0c8857 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -179,12 +179,13 @@ escape_encode(PyObject *self, PyObject *str; const char *errors = NULL; char *buf; - Py_ssize_t len; + Py_ssize_t consumed, len; - if (!PyArg_ParseTuple(args, "O!|z:escape_encode", - &PyString_Type, &str, &errors)) + if (!PyArg_ParseTuple(args, "S|z:escape_encode", + &str, &errors)) return NULL; + consumed = PyString_GET_SIZE(str); str = PyString_Repr(str, 0); if (!str) return NULL; @@ -196,7 +197,7 @@ escape_encode(PyObject *self, if (_PyString_Resize(&str, len-2) < 0) return NULL; - return codec_tuple(str, PyString_Size(str)); + return codec_tuple(str, consumed); } #ifdef Py_USING_UNICODE |