summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-06-12 04:50:11 -0700
committerGitHub <noreply@github.com>2019-06-12 04:50:11 -0700
commitd561f848b235f2011a43b705d112055b92fa2366 (patch)
tree17367ffd5a657840af191bbedb1b99befbf8d38e /Modules
parent534136ac6790a701e24f364a9b7f1e34bf5f3ce7 (diff)
downloadcpython-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.c5
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)