Fix stdoutEncode mangling non-string values used by REST API (#6054) (#6056)

Co-authored-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com>
This commit is contained in:
ChrisJr404 2026-05-02 02:57:16 -04:00 committed by GitHub
parent 4489b2c0d2
commit 026e5d05f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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")