# HG changeset patch # User Thomas De Schampheleire # Date 2020-10-19 12:47:50 # Node ID 73ba6abe60dbdea286bc38ed0614dbddc06e986c # Parent e05fe780bc01068649583e9f8397a04c40c60d43 lib/diffs: make sure that trailing tabs are indicated Backport of 53142fd5af4e - the problem also existed before f79c40759d6f. Eat trailing newline after trailing tab as we already do for trailing spaces. The change diff mainly shows re group numbers shifting. 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)(\n|$)?|(\r)|(?<=.)( \n| $)') def _escaper(string): @@ -470,10 +470,12 @@ def _escaper(string): if groups[2]: return '>' if groups[3]: + if groups[4] is not None: # end of line + return '\t' return '\t' - if groups[4]: + if groups[5]: return '' - if groups[5]: + if groups[6]: return ' ' assert False diff --git a/kallithea/tests/models/test_diff_parsers.py b/kallithea/tests/models/test_diff_parsers.py --- a/kallithea/tests/models/test_diff_parsers.py +++ b/kallithea/tests/models/test_diff_parsers.py @@ -297,13 +297,13 @@ class TestDiffLib(base.TestController): assert s == r''' context ... ... '@@ -51,6 +51,13 @@\n' unmod 51 51 '\tbegin();\n' -unmod 52 52 '\t\n' +unmod 52 52 '\t' add 53 '\tint foo;\n' add 54 '\tint bar; \n' add 55 '\tint baz;\t\n' add 56 '\tint space; ' -add 57 '\tint tab;\t\n' -add 58 '\t\n' +add 57 '\tint tab;\t' +add 58 '\t' unmod 59 53 ' ' del 54 '\t#define MAX_STEPS (48)\n' add 60 '\t\n'