From: Serhiy Storchaka Date: Fri, 31 May 2019 08:29:39 +0000 (+0300) Subject: bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859) X-Git-Tag: v3.8.0b1~105 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38ab7d4721b422547f7b46b9d68968863fa70573;p=python 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. --- diff --git a/Lib/pickle.py b/Lib/pickle.py index cb768b2858..a67ac7dd8b 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -852,7 +852,10 @@ class _Pickler: self.write(BINUNICODE + pack("= 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)