cpython: 5e98a50e0f55 (original) (raw)

--- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2807,6 +2807,9 @@ class CodePageTest(unittest.TestCase): ('[\u20ac]', 'replace', b'[?]'), ('[\xff]', 'backslashreplace', b'[\xff]'), ('[\xff]', 'xmlcharrefreplace', b'[ΓΏ]'),

@@ -2816,6 +2819,7 @@ class CodePageTest(unittest.TestCase): (b'[\xff]', 'ignore', '[]'), (b'[\xff]', 'replace', '[\ufffd]'), (b'[\xff]', 'surrogateescape', '[\udcff]'),

@@ -2826,14 +2830,23 @@ class CodePageTest(unittest.TestCase): ('abc', 'strict', b'abc'), ('\xe9\u20ac', 'strict', b'\xe9\x80'), ('\xff', 'strict', b'\xff'),

def test_cp_utf7(self):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -84,6 +84,9 @@ Core and Builtins Library ------- +- Issue #13916: Disallowed the surrogatepass error handler for non UTF-*

--- a/Python/codecs.c +++ b/Python/codecs.c @@ -901,6 +901,7 @@ PyObject *PyCodec_BackslashReplaceErrors } } +#define ENC_UNKNOWN -1 #define ENC_UTF8 0 #define ENC_UTF16BE 1 #define ENC_UTF16LE 2 @@ -916,7 +917,11 @@ get_standard_encoding(const char *encodi encoding += 3; if (*encoding == '-' || *encoding == '_' ) encoding++;

@@ -955,9 +960,7 @@ get_standard_encoding(const char *encodi } } }

} /* This handler is declared static until someone demonstrates @@ -994,6 +997,12 @@ PyCodec_SurrogatePassErrors(PyObject *ex } code = get_standard_encoding(encoding, &bytelength); Py_DECREF(encode);

res = PyBytes_FromStringAndSize(NULL, bytelength*(end-start)); if (!res) { @@ -1068,6 +1077,12 @@ PyCodec_SurrogatePassErrors(PyObject *ex } code = get_standard_encoding(encoding, &bytelength); Py_DECREF(encode);

/* Try decoding a single surrogate character. If there are more, let the codec call us again. */