diff --git a/raven/processors.py b/raven/processors.py index b097bc1a8..c091d6aa0 100644 --- a/raven/processors.py +++ b/raven/processors.py @@ -99,8 +99,11 @@ def filter_http(self, data): if n not in data: continue - if isinstance(data[n], six.string_types) and '=' in data[n]: + if ((isinstance(data[n], six.string_types) and '=' in data[n]) or + isinstance(data[n], six.binary_type)): # at this point we've assumed it's a standard HTTP query + if isinstance(data[n], six.binary_type): + data[n] = data[n].decode() querybits = [] for bit in data[n].split('&'): chunk = bit.split('=') diff --git a/tests/processors/tests.py b/tests/processors/tests.py index 041aa7216..b11355739 100644 --- a/tests/processors/tests.py +++ b/tests/processors/tests.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import six from mock import Mock import raven @@ -119,6 +120,20 @@ def test_http(self): self.assertTrue(n in http) self._check_vars_sanitized(http[n], proc) + def test_http_data_as_bytes(self): + data = get_http_data() + data['request']['data'] = six.b( + 'foo=bar&password=secury') + + proc = SanitizePasswordsProcessor(Mock()) + result = proc.process(data) + + self.assertTrue('request' in result) + http = result['request'] + + self.assertEqual( + http['data'], 'foo=bar&password=%(m)s' % dict(m=proc.MASK)) + def test_querystring_as_string(self): data = get_http_data() data['request']['query_string'] = 'foo=bar&password=hello&the_secret=hello'\