diff options
author | Renaud Paquay <rpaquay@google.com> | 2020-02-21 09:32:27 -0800 |
---|---|---|
committer | Renaud Paquay <rpaquay@google.com> | 2020-02-24 16:49:25 +0000 |
commit | a3fef9b2a2bb3b5e7251b1d81cb60354bbca93f7 (patch) | |
tree | 99962e1fe2dacddc3a8d1374d3736e44502aaa1b | |
parent | a0ae161563799175f219a5062914618951525b88 (diff) | |
download | repohooks-a3fef9b2a2bb3b5e7251b1d81cb60354bbca93f7.tar.gz |
Fix pre-upload hook on Windows (python 2.7)
Using str.decode converts the resulting string into unicode on Windows.
This is not expected, as most strings are expected to be non-unicode when
running scripts with Python 2.7. In this case, the strings returned
by "run_command" sometimes end up in the environment variables used to
create a sub-process, and Python 2.7 does not support unicode strings
for the process creation API.
Calling "str()" on the result of "decode()" ensures the string is converted
back to an 8-bit string. On non-Windows platform (and on Python 3+), the
call is a no-op.
This issue was introduced by a recent rebase/merge of the repohooks
repository.
Test: Manual (on a Windows machine)
Bug: 150001153
Bug: 149406150
Change-Id: I67f4c7ee9700c8082e3d965a3dc8ec5bec91955b
-rw-r--r-- | rh/utils.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/rh/utils.py b/rh/utils.py index b3ed338..eae7bcf 100644 --- a/rh/utils.py +++ b/rh/utils.py @@ -457,9 +457,9 @@ def run_command(cmd, error_message=None, redirect_stdout=False, # Make sure output is returned as a string rather than bytes. if cmd_result.output is not None: - cmd_result.output = cmd_result.output.decode('utf-8', 'replace') + cmd_result.output = str(cmd_result.output.decode('utf-8', 'replace')) if cmd_result.error is not None: - cmd_result.error = cmd_result.error.decode('utf-8', 'replace') + cmd_result.error = str(cmd_result.error.decode('utf-8', 'replace')) return cmd_result # pylint: enable=redefined-builtin,input-builtin |