##// END OF EJS Templates
templatefilters: defend against evil unicode strs in json filter...
Augie Fackler -
r34838:4fdc4adb default
parent child Browse files
Show More
@@ -13,6 +13,7 b' import time'
13
13
14 from . import (
14 from . import (
15 encoding,
15 encoding,
16 error,
16 hbisect,
17 hbisect,
17 node,
18 node,
18 pycompat,
19 pycompat,
@@ -233,6 +234,13 b' def json(obj, paranoid=True):'
233 return pycompat.bytestr(obj)
234 return pycompat.bytestr(obj)
234 elif isinstance(obj, bytes):
235 elif isinstance(obj, bytes):
235 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
236 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
237 elif isinstance(obj, str):
238 # This branch is unreachable on Python 2, because bytes == str
239 # and we'll return in the next-earlier block in the elif
240 # ladder. On Python 3, this helps us catch bugs before they
241 # hurt someone.
242 raise error.ProgrammingError(
243 'Mercurial only does output with bytes on Python 3: %r' % obj)
236 elif util.safehasattr(obj, 'keys'):
244 elif util.safehasattr(obj, 'keys'):
237 out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid),
245 out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid),
238 json(v, paranoid))
246 json(v, paranoid))
General Comments 0
You need to be logged in to leave comments. Login now