mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
ba0430211f
commit
38ab7d4721
4 changed files with 25 additions and 5 deletions
|
@ -852,7 +852,10 @@ class _Pickler:
|
|||
self.write(BINUNICODE + pack("<I", n) + encoded)
|
||||
else:
|
||||
obj = obj.replace("\\", "\\u005c")
|
||||
obj = obj.replace("\0", "\\u0000")
|
||||
obj = obj.replace("\n", "\\u000a")
|
||||
obj = obj.replace("\r", "\\u000d")
|
||||
obj = obj.replace("\x1a", "\\u001a") # EOF on DOS
|
||||
self.write(UNICODE + obj.encode('raw-unicode-escape') +
|
||||
b'\n')
|
||||
self.memoize(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue