comparison mercurial/templatefilters.py @ 26843:f580c78ea667

uescape: also encode non-printable char under 128 We were assuming everything under 128 was printable ascii, but there are a lot of control characters in that range that can't simply be included in json and other targets. We forcibly encode everything under 32, because they are either control char or oddly printable (like tab or line ending). We also add the hypothesis-powered test that caught this.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 02 Nov 2015 11:56:59 +0000
parents 7012be5ab5bd
children f9984f76fd90
comparison
equal deleted inserted replaced
26842:0f76c64f5cc3 26843:f580c78ea667
217 return json(obj()) 217 return json(obj())
218 else: 218 else:
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)
226 226
227 _escapes = [ 227 _escapes = [