From eda2b565b009448ebd82a2b648c6589cdccd142c Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Sun, 12 Feb 2023 14:07:50 +0700 Subject: [PATCH 1/2] Don't emit a trailng newline in base64-encoded data like 'image/png' --- jupyter_client/jsonutil.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_client/jsonutil.py b/jupyter_client/jsonutil.py index 8532cc35..db46d1b1 100644 --- a/jupyter_client/jsonutil.py +++ b/jupyter_client/jsonutil.py @@ -111,7 +111,7 @@ def json_default(obj): return obj.isoformat().replace('+00:00', 'Z') if isinstance(obj, bytes): - return b2a_base64(obj).decode('ascii') + return b2a_base64(obj, newline=False).decode('ascii') if isinstance(obj, Iterable): return list(obj) @@ -157,7 +157,7 @@ def json_clean(obj): if isinstance(obj, bytes): # unanmbiguous binary data is base64-encoded # (this probably should have happened upstream) - return b2a_base64(obj).decode('ascii') + return b2a_base64(obj, newline=False).decode('ascii') if isinstance(obj, container_to_list) or ( hasattr(obj, '__iter__') and hasattr(obj, next_attr_name) From e7eb5d1753b3647fe12c604a62bcc9d24ea0725d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 12 Feb 2023 13:08:10 -0600 Subject: [PATCH 2/2] update test --- tests/test_jsonutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_jsonutil.py b/tests/test_jsonutil.py index a3074b5c..3b029fcd 100644 --- a/tests/test_jsonutil.py +++ b/tests/test_jsonutil.py @@ -166,7 +166,7 @@ def test_json_default(): (True, None), (False, None), (None, None), - ({"key": b"\xFF"}, {"key": "/w==\n"}), + ({"key": b"\xFF"}, {"key": "/w=="}), # Containers ([1, 2], None), ((1, 2), [1, 2]),