Skip to content

Commit

Permalink
Sanitizes log message input (#479)
Browse files Browse the repository at this point in the history
* Sanitizes log message input

Fixes issue #478 in which invalid utf-8 characters that appeared in test
output were causing unhandled exceptions to be raised. The fix uses
built-in sanitization features to replace invalid characters with '?'.

* Fixes Python2/3 queue import error in test code

* Fixes unknown 'to_bytes' unittest for Python2
  • Loading branch information
yamokosk authored and wjwwood committed Aug 1, 2017
1 parent da79d37 commit cb4a98b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion catkin_tools/execution/io.py
Expand Up @@ -128,7 +128,7 @@ def _decode(self, data):
"""Decode bytes into Python str.
:type data: bytes
"""
return data.decode('utf-8')
return data.decode('utf-8', 'replace')

def __del__(self):
if self.is_open:
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_io.py
@@ -0,0 +1,18 @@
try:
# Python3
from queue import Queue
except ImportError:
# Python2
from Queue import Queue

import binascii
from catkin_tools.execution import io as io


def test_invalid_utf8_characters():
io_container = io.IOBufferContainer('test', 'test_id', 'test', Queue(), '/tmp')
bad_byte_array = binascii.a2b_hex(b'80')
try:
io_container._decode(bad_byte_array)
except UnicodeDecodeError:
assert False, "Bad decoding"

0 comments on commit cb4a98b

Please sign in to comment.