File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed
Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -260,11 +260,25 @@ def safe_repr(value):
260260 rv = repr (value )
261261 if isinstance (rv , bytes ):
262262 rv = rv .decode ("utf-8" , "replace" )
263+
264+ # At this point `rv` contains a bunch of literal escape codes, like
265+ # this (exaggerated example):
266+ #
267+ # u"\\x2f"
268+ #
269+ # But we want to show this string as:
270+ #
271+ # u"/"
263272 try :
264- return rv .encode ("utf-8" ).decode ("unicode-escape" )
273+ # unicode-escape does this job, but can only decode latin1. So we
274+ # attempt to encode in latin1.
275+ return rv .encode ("latin1" ).decode ("unicode-escape" )
265276 except Exception :
277+ # Since usually strings aren't latin1 this can break. In those
278+ # cases we just give up.
266279 return rv
267280 except Exception :
281+ # If e.g. the call to `repr` already fails
268282 return u"<broken repr>"
269283
270284
Original file line number Diff line number Diff line change 1+ # coding: utf-8
12import sys
23import os
34
4- from hypothesis import given , assume
5+ from hypothesis import given
56import hypothesis .strategies as st
67
78from sentry_sdk .utils import safe_repr , exceptions_from_error_tuple
@@ -17,15 +18,8 @@ def test_safe_repr_never_broken_for_strings(x):
1718 assert u"broken repr" not in r
1819
1920
20- @given (x = any_string )
21- def test_safe_repr_never_leaves_escapes_in (x ):
22- if isinstance (x , bytes ):
23- assume (b"\\ u" not in x and b"\\ x" not in x )
24- else :
25- assume (u"\\ u" not in x and u"\\ x" not in x )
26- r = safe_repr (x )
27- assert isinstance (r , text_type )
28- assert u"\\ u" not in r and u"\\ x" not in r
21+ def test_safe_repr_regressions ():
22+ assert u"лошадь" in safe_repr (u"лошадь" )
2923
3024
3125def test_abs_path ():
You can’t perform that action at this time.
0 commit comments