Skip to content

Commit

Permalink
ansible-test yamllint: fix UnicodeDecodeError (#55364)
Browse files Browse the repository at this point in the history
* ansible-test yamllint: fix UnicodeDecodeError

* Conditional fix

(cherry picked from commit f8bebc6)
  • Loading branch information
mkrizek authored and mattclay committed Apr 22, 2019
1 parent c1b640b commit 3ae0296
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/runner/lib/util.py
Expand Up @@ -381,7 +381,10 @@ def raw_command(cmd, capture=False, env=None, data=None, cwd=None, explain=False

if communicate:
encoding = 'utf-8'
data_bytes = data.encode(encoding, 'surrogateescape') if data else None
if data is None or isinstance(data, bytes):
data_bytes = data
else:
data_bytes = data.encode(encoding, 'surrogateescape')
stdout_bytes, stderr_bytes = process.communicate(data_bytes)
stdout_text = stdout_bytes.decode(encoding, str_errors) if stdout_bytes else u''
stderr_text = stderr_bytes.decode(encoding, str_errors) if stderr_bytes else u''
Expand Down

0 comments on commit 3ae0296

Please sign in to comment.