From 10cb96b511ca2430ef0d9dcbf877d6fb306ae70f Mon Sep 17 00:00:00 2001 From: Jeff Allen Date: Sat, 23 Dec 2023 10:03:56 +0000 Subject: [PATCH 1/4] Fix GH-113028 divergence in pickling str 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. --- Lib/pickle.py | 14 +++++++------- Lib/test/pickletester.py | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index 4f5ad5b71e8899..988c0887341310 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -857,13 +857,13 @@ def save_str(self, obj): else: self.write(BINUNICODE + pack(" Date: Sat, 23 Dec 2023 15:35:04 +0000 Subject: [PATCH 2/4] Add comment as to intent of test --- Lib/test/pickletester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index bd5660b63fab54..74b82caf742f20 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1826,7 +1826,7 @@ def test_unicode_high_plane(self): self.assert_is_copy(t, t2) def test_unicode_memoization(self): - # gh- + # 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) From bf56b178ceb5e615a2bbe07cb595c9fdf1e908eb Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:51:17 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst diff --git a/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst b/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst new file mode 100644 index 00000000000000..d4255b4b6cffcc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst @@ -0,0 +1 @@ +When a second reference to a string appears in the input to `pickle`, and the Python implementation is in use, we are guaranteed that a single copy gets pickled and is shared when reloaded. Previously, in protocol 0, when a string contained certain characters (e.g. newline) it resulted in duplicate objects. From 7e25cc85119000ba47504c7c790acffc593c2b89 Mon Sep 17 00:00:00 2001 From: Jeff Allen Date: Sat, 23 Dec 2023 17:36:18 +0000 Subject: [PATCH 4/4] Hand-edit blurb for readability and to satisfy lint. --- .../Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst b/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst index d4255b4b6cffcc..5f66d6a00b4d3d 100644 --- a/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst +++ b/Misc/NEWS.d/next/Library/2023-12-23-16-51-17.gh-issue-113028.3Jmdoj.rst @@ -1 +1,6 @@ -When a second reference to a string appears in the input to `pickle`, and the Python implementation is in use, we are guaranteed that a single copy gets pickled and is shared when reloaded. Previously, in protocol 0, when a string contained certain characters (e.g. newline) it resulted in duplicate objects. +When a second reference to a string appears in the input to :mod:`pickle`, +and the Python implementation is in use, +we are guaranteed that a single copy gets pickled +and a single object is shared when reloaded. +Previously, in protocol 0, when a string contained certain characters +(e.g. newline) it resulted in duplicate objects.