Skip to content

Commit 8af6c20

Browse files
authored
xcresult_logs.py: Fix potential UnicodeEncodeError (#9645)
1 parent 626ec68 commit 8af6c20

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

scripts/xcresult_logs.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ def main():
6464
# but also makes it harder to deal with.
6565
log_id = find_log_id(xcresult_path)
6666
log = export_log(xcresult_path, log_id)
67-
sys.stdout.write(log)
67+
68+
# Avoid a potential UnicodeEncodeError raised by sys.stdout.write() by
69+
# doing a relaxed encoding ourselves.
70+
if hasattr(sys.stdout, 'buffer'):
71+
log_encoded = log.encode('utf8', errors='backslashreplace')
72+
sys.stdout.flush()
73+
sys.stdout.buffer.write(log_encoded)
74+
else:
75+
log_encoded = log.encode('ascii', errors='backslashreplace')
76+
log_decoded = log_encoded.decode('ascii', errors='strict')
77+
sys.stdout.write(log_decoded)
6878

6979

7080
# Most flags on the xcodebuild command-line are uninteresting, so only pull

0 commit comments

Comments
 (0)