From 5adf0fa1081ff02d8614022edc23ae383f71674b Mon Sep 17 00:00:00 2001 From: "Chris (ChrisJr404)" <11917633+ChrisJr404@users.noreply.github.com> Date: Fri, 1 May 2026 17:41:44 -0400 Subject: [PATCH] Fix stdoutEncode mangling non-string values used by REST API (#6054) --- 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 0b4cddd739e..c8286e3f3e7 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")