diff options
author | Jeff Allen <ja.py@farowl.co.uk> | 2023-12-24 09:43:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-24 09:43:44 (GMT) |
commit | 08398631a0298dcf785ee7bd0e26c7844823ce59 (patch) | |
tree | f669f700f6f6b5b91d59825045c00f7dbae4e408 /Lib/test/pickletester.py | |
parent | 894f0e573d9eb49cd5864c44328f10a731852dab (diff) | |
download | cpython-08398631a0298dcf785ee7bd0e26c7844823ce59.zip cpython-08398631a0298dcf785ee7bd0e26c7844823ce59.tar.gz cpython-08398631a0298dcf785ee7bd0e26c7844823ce59.tar.bz2 |
gh-113028: Correctly memoize str in pickle when escapes added (GH-113436)
This fixes a divergence between the Python and C implementations of pickle
for protocol 0, such that it pickle.py fails to re-use the first pickled
representation of strings involving characters that have to be escaped.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index fd446c8..74b82ca 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1825,6 +1825,14 @@ class AbstractPickleTests: t2 = self.loads(p) self.assert_is_copy(t, t2) + def test_unicode_memoization(self): + # Repeated str is re-used (even when escapes added). + for proto in protocols: + for s in '', 'xyz', 'xyz\n', 'x\\yz', 'x\xa1yz\r': + p = self.dumps((s, s), proto) + s1, s2 = self.loads(p) + self.assertIs(s1, s2) + def test_bytes(self): for proto in protocols: for s in b'', b'xyz', b'xyz'*100: |