diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-06-12 04:50:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-12 04:50:11 -0700 |
commit | d561f848b235f2011a43b705d112055b92fa2366 (patch) | |
tree | 17367ffd5a657840af191bbedb1b99befbf8d38e /Modules | |
parent | 534136ac6790a701e24f364a9b7f1e34bf5f3ce7 (diff) | |
download | cpython-git-d561f848b235f2011a43b705d112055b92fa2366.tar.gz |
bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859)
Escape ``\r``, ``\0`` and ``\x1a`` (end-of-file on Windows) in Unicode strings.
(cherry picked from commit 38ab7d4721b422547f7b46b9d68968863fa70573)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_pickle.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c index c8b3ef70f5..9a6207b519 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -2337,7 +2337,10 @@ raw_unicode_escape(PyObject *obj) *p++ = Py_hexdigits[ch & 15]; } /* Map 16-bit characters, '\\' and '\n' to '\uxxxx' */ - else if (ch >= 256 || ch == '\\' || ch == '\n') { + else if (ch >= 256 || + ch == '\\' || ch == 0 || ch == '\n' || ch == '\r' || + ch == 0x1a) + { /* -1: subtract 1 preallocated byte */ p = _PyBytesWriter_Prepare(&writer, p, 6-1); if (p == NULL) |