diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py
--- a/kallithea/lib/diffs.py
+++ b/kallithea/lib/diffs.py
@@ -453,7 +453,7 @@ class DiffProcessor(object):
return self.adds, self.removes
-_escape_re = re.compile(r'(&)|(<)|(>)|(\t)|(\r)|(?<=.)( \n| $)')
+_escape_re = re.compile(r'(&)|(<)|(>)|(\t)|(\r)|(?<=.)( \n| $)|(\t\n|\t$)')
def _escaper(string):
@@ -470,11 +470,13 @@ def _escaper(string):
if groups[2]:
return '>'
if groups[3]:
- return '\t'
+ return '\t' # Note: trailing tabs will get a longer match later
if groups[4]:
return ''
if groups[5]:
return ' '
+ if groups[6]:
+ return '\t'
assert False
return _escape_re.sub(substitute, safe_str(string))