Skip to content

Commit e77ad89

Browse files
authored
Don't emit a trailng newline in base64-encoded data like 'image/png' (#931)
1 parent 557530b commit e77ad89

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

jupyter_client/jsonutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def json_default(obj):
111111
return obj.isoformat().replace('+00:00', 'Z')
112112

113113
if isinstance(obj, bytes):
114-
return b2a_base64(obj).decode('ascii')
114+
return b2a_base64(obj, newline=False).decode('ascii')
115115

116116
if isinstance(obj, Iterable):
117117
return list(obj)
@@ -157,7 +157,7 @@ def json_clean(obj):
157157
if isinstance(obj, bytes):
158158
# unanmbiguous binary data is base64-encoded
159159
# (this probably should have happened upstream)
160-
return b2a_base64(obj).decode('ascii')
160+
return b2a_base64(obj, newline=False).decode('ascii')
161161

162162
if isinstance(obj, container_to_list) or (
163163
hasattr(obj, '__iter__') and hasattr(obj, next_attr_name)

tests/test_jsonutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_json_default():
166166
(True, None),
167167
(False, None),
168168
(None, None),
169-
({"key": b"\xFF"}, {"key": "/w==\n"}),
169+
({"key": b"\xFF"}, {"key": "/w=="}),
170170
# Containers
171171
([1, 2], None),
172172
((1, 2), [1, 2]),

0 commit comments

Comments
 (0)