diff 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
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Sat Oct 24 12:46:03 2015 +0100
+++ b/mercurial/templatefilters.py	Mon Nov 02 11:56:59 2015 +0000
@@ -219,7 +219,7 @@
         raise TypeError('cannot encode type %s' % obj.__class__.__name__)
 
 def _uescape(c):
-    if ord(c) < 0x80:
+    if 0x20 <= ord(c) < 0x80:
         return c
     else:
         return '\\u%04x' % ord(c)