##// END OF EJS Templates
templatefilters: drop old jsonescape() function...
Yuya Nishihara -
r28213:93b5c540 default
parent child Browse files
Show More
@@ -215,23 +215,6 b' def json(obj):'
215 else:
215 else:
216 raise TypeError('cannot encode type %s' % obj.__class__.__name__)
216 raise TypeError('cannot encode type %s' % obj.__class__.__name__)
217
217
218 def _uescape(c):
219 if 0x20 <= ord(c) < 0x80:
220 return c
221 else:
222 return '\\u%04x' % ord(c)
223
224 _escapes = [
225 ('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'), ('\n', '\\n'),
226 ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'),
227 ('<', '\\u003c'), ('>', '\\u003e'), ('\0', '\\u0000')
228 ]
229
230 def jsonescape(s):
231 for k, v in _escapes:
232 s = s.replace(k, v)
233 return ''.join(_uescape(c) for c in s)
234
235 def lower(text):
218 def lower(text):
236 """:lower: Any text. Converts the text to lowercase."""
219 """:lower: Any text. Converts the text to lowercase."""
237 return encoding.lower(text)
220 return encoding.lower(text)
@@ -44,17 +44,4 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
60 $ cd ..
47 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now