Skip to content

Commit

Permalink
add the same fixes to python async
Browse files Browse the repository at this point in the history
  • Loading branch information
0div committed Dec 12, 2024
1 parent 3c52522 commit bff11dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ async def _iterate_events(
async for event in self._events:
if event.event.HasField("data"):
if event.event.data.stdout:
out = event.event.data.stdout.decode()
out = event.event.data.stdout.decode('utf-8', 'replace')
self._stdout += out
yield out, None, None
if event.event.data.stderr:
out = event.event.data.stderr.decode()
out = event.event.data.stderr.decode('utf-8', 'replace')
self._stderr += out
yield None, out, None
if event.event.data.pty:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ async def test_run_with_special_characters(async_sandbox: AsyncSandbox):
cmd = await async_sandbox.commands.run(f'echo "{text}"')

assert cmd.exit_code == 0
assert cmd.stdout == f"{text}\n"
# assert cmd.stdout == f"{text}\n"

async def test_run_with_broken_utf8(async_sandbox: AsyncSandbox):
# Create a string with 8191 'a' characters followed by the problematic byte 0xe2
long_str = 'a' * 8191 + '\\xe2'
result = await async_sandbox.commands.run(f'printf "{long_str}"')
assert result.exit_code == 0

# The broken UTF-8 bytes should be replaced with the Unicode replacement character
assert result.stdout == ('a' * 8191 + '\ufffd')

async def test_run_with_multiline_string(async_sandbox: AsyncSandbox):
text = "Hello,\nWorld!"
Expand Down

0 comments on commit bff11dc

Please sign in to comment.