##// END OF EJS Templates
uescape: also encode non-printable char under 128...
Pierre-Yves David -
r26843:f580c78e default
parent child Browse files
Show More
@@ -219,7 +219,7 b' def json(obj):'
219 raise TypeError('cannot encode type %s' % obj.__class__.__name__)
219 raise TypeError('cannot encode type %s' % obj.__class__.__name__)
220
220
221 def _uescape(c):
221 def _uescape(c):
222 if ord(c) < 0x80:
222 if 0x20 <= ord(c) < 0x80:
223 return c
223 return c
224 else:
224 else:
225 return '\\u%04x' % ord(c)
225 return '\\u%04x' % ord(c)
@@ -44,4 +44,17 b''
44 0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000
44 0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000
45 -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000
45 -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000
46
46
47 Fuzzing the unicode escaper to ensure it produces valid data
48
49 #if hypothesis
50
51 >>> from hypothesishelpers import *
52 >>> import mercurial.templatefilters as tf
53 >>> import json
54 >>> @check(st.text().map(lambda s: s.encode('utf-8')))
55 ... def testtfescapeproducesvalidjson(text):
56 ... json.loads('"' + tf.jsonescape(text) + '"')
57
58 #endif
59
47 $ cd ..
60 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now