Skip to content

Commit 026e5d0

Browse files
authored
Fix stdoutEncode mangling non-string values used by REST API (#6054) (#6056)
Co-authored-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com>
1 parent 4489b2c commit 026e5d0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/core/convert.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ def stdoutEncode(value):
412412
Returns textual representation of a given value safe for writing to stdout
413413
>>> stdoutEncode(b"foobar")
414414
'foobar'
415+
>>> stdoutEncode({"url": "http://example.com/foo", "data": "id=1"}) == {"url": "http://example.com/foo", "data": "id=1"}
416+
True
415417
"""
416418

417419
if value is None:
@@ -437,7 +439,11 @@ def stdoutEncode(value):
437439
if isinstance(value, (bytes, bytearray)):
438440
value = getUnicode(value, encoding)
439441
elif not isinstance(value, str):
440-
value = str(value)
442+
# Non-string values (e.g. dicts passed through the REST API path,
443+
# where the overridden sys.stdout.write JSON-encodes the value)
444+
# must be returned unchanged — stringifying them via str() yields
445+
# Python repr() output that the API consumer cannot parse.
446+
return value
441447

442448
try:
443449
retVal = value.encode(encoding, errors="replace").decode(encoding, errors="replace")

0 commit comments

Comments
 (0)