diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-05-31 08:29:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-31 08:29:39 (GMT) |
commit | 38ab7d4721b422547f7b46b9d68968863fa70573 (patch) | |
tree | aac2c1543f721338b6cf665e9d289ccad43a8af6 /Modules | |
parent | ba0430211f5101c9d748d72b03926ca79c5252a8 (diff) | |
download | cpython-38ab7d4721b422547f7b46b9d68968863fa70573.zip cpython-38ab7d4721b422547f7b46b9d68968863fa70573.tar.gz cpython-38ab7d4721b422547f7b46b9d68968863fa70573.tar.bz2 |
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.
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 57145be..34e11bd 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -2588,7 +2588,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) |