]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Minimal fix for the complaints about pickling Unicode objects. (SF
authorGuido van Rossum <guido@python.org>
Tue, 19 Dec 2000 01:29:00 +0000 (01:29 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 19 Dec 2000 01:29:00 +0000 (01:29 +0000)
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.

Lib/pickle.py

index c26c2e533ffbd08ae3972f82971df680f9518b09..fb9448e97717fe3ae515a33c123e1f19bdac6fcb 100644 (file)
@@ -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)