Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 20655d1

Browse files
prokaktusashwoods
authored andcommitted
Fix skipping sanitizer for bytes data in filter_http
1 parent c7ac0b7 commit 20655d1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

raven/processors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import re
1111

12-
from raven.utils.compat import string_types, text_type
12+
from raven.utils.compat import string_types, text_type, PY3
1313
from raven.utils import varmap
1414

1515

@@ -110,6 +110,10 @@ def filter_http(self, data):
110110
if n not in data:
111111
continue
112112

113+
# data could be provided as bytes
114+
if PY3 and isinstance(data[n], bytes):
115+
data[n] = data[n].decode('utf-8', 'replace')
116+
113117
if isinstance(data[n], string_types) and '=' in data[n]:
114118
# at this point we've assumed it's a standard HTTP query
115119
# or cookie

tests/contrib/django/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_djangorestframeworkcompatmiddleware_fills_request_data(self):
209209
content_type='application/json')
210210
assert len(self.raven.events) == 1
211211
event = self.raven.events.pop(0)
212-
assert event['request']['data'] == b'{"a":"b"}'
212+
assert event['request']['data'] == '{"a":"b"}'
213213

214214
def test_capture_event_with_request_middleware(self):
215215
path = reverse('sentry-trigger-event')

tests/processors/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ def test_sanitize_non_ascii(self):
357357
result = proc.sanitize('__repr__: жили-были', '42')
358358
self.assertEquals(result, '42')
359359

360+
def test_sanitize_bytes(self):
361+
proc = SanitizePasswordsProcessor(Mock())
362+
data = {'data': b'password=1234'}
363+
result = proc.filter_http(data)
364+
self.assertIn(data['data'], 'password=%s' % proc.MASK)
365+
360366

361367
class RemovePostDataProcessorTest(TestCase):
362368
def test_does_remove_data(self):

0 commit comments

Comments
 (0)