diff options
author | Guido van Rossum <guido@python.org> | 2000-12-19 01:29:00 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-12-19 01:29:00 (GMT) |
commit | a31b4ef7c526b7f17620024248d11a631ef59644 (patch) | |
tree | f2220ffd26502e5ff5dc2ab0ef2c6d68487a27a6 | |
parent | 20d3fc071bb16bb63333de4bb4d66fd0e7f68b64 (diff) | |
download | cpython-a31b4ef7c526b7f17620024248d11a631ef59644.zip cpython-a31b4ef7c526b7f17620024248d11a631ef59644.tar.gz cpython-a31b4ef7c526b7f17620024248d11a631ef59644.tar.bz2 |
Minimal fix for the complaints about pickling Unicode objects. (SF
bugs #126161 and 123634).
The solution doesn't use the unicode-escape encoding; that has other
problems (it seems not 100% reversible). Rather, it transforms the
input Unicode object slightly before encoding it using
raw-unicode-escape, so that the decoding will reconstruct the original
string: backslash and newline characters are translated into their
\uXXXX counterparts.
This is backwards incompatible for strings containing backslashes, but
for some of those strings, the pickling was already broken.
-rw-r--r-- | Lib/pickle.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index c26c2e5..fb9448e 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -291,6 +291,8 @@ class Pickler: s = mdumps(l)[1:] self.write(BINUNICODE + s + encoding) else: + object = object.replace(u"\\", u"\\u005c") + object = object.replace(u"\n", u"\\u000a") self.write(UNICODE + object.encode('raw-unicode-escape') + '\n') memo_len = len(memo) |