From 026e5d05f44fdd954ccb85dc01dc09f98fabc51e Mon Sep 17 00:00:00 2001 From: ChrisJr404 Date: Sat, 2 May 2026 02:57:16 -0400 Subject: [PATCH] Fix stdoutEncode mangling non-string values used by REST API (#6054) (#6056) Co-authored-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com> --- lib/core/convert.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/core/convert.py b/lib/core/convert.py index 0b4cddd73..c8286e3f3 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -412,6 +412,8 @@ def stdoutEncode(value): Returns textual representation of a given value safe for writing to stdout >>> stdoutEncode(b"foobar") 'foobar' + >>> stdoutEncode({"url": "http://example.com/foo", "data": "id=1"}) == {"url": "http://example.com/foo", "data": "id=1"} + True """ if value is None: @@ -437,7 +439,11 @@ def stdoutEncode(value): if isinstance(value, (bytes, bytearray)): value = getUnicode(value, encoding) elif not isinstance(value, str): - value = str(value) + # Non-string values (e.g. dicts passed through the REST API path, + # where the overridden sys.stdout.write JSON-encodes the value) + # must be returned unchanged — stringifying them via str() yields + # Python repr() output that the API consumer cannot parse. + return value try: retVal = value.encode(encoding, errors="replace").decode(encoding, errors="replace")