changeset 8506:73ba6abe60db stable

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.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Mon, 19 Oct 2020 12:47:50 +0200
parents e05fe780bc01
children 213450cbdc11
files kallithea/lib/diffs.py kallithea/tests/models/test_diff_parsers.py
diffstat 2 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Sat Nov 07 01:58:33 2020 +0100
+++ b/kallithea/lib/diffs.py	Mon Oct 19 12:47:50 2020 +0200
@@ -453,7 +453,7 @@
         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 @@
         if groups[2]:
             return '&gt;'
         if groups[3]:
+            if groups[4] is not None:  # end of line
+                return '<u>\t</u><i></i>'
             return '<u>\t</u>'
-        if groups[4]:
+        if groups[5]:
             return '<u class="cr"></u>'
-        if groups[5]:
+        if groups[6]:
             return ' <i></i>'
         assert False
 
--- a/kallithea/tests/models/test_diff_parsers.py	Sat Nov 07 01:58:33 2020 +0100
+++ b/kallithea/tests/models/test_diff_parsers.py	Mon Oct 19 12:47:50 2020 +0200
@@ -297,13 +297,13 @@
         assert s == r'''
 context ... ... '@@ -51,6 +51,13 @@\n'
 unmod    51  51 '<u>\t</u>begin();\n'
-unmod    52  52 '<u>\t</u>\n'
+unmod    52  52 '<u>\t</u><i></i>'
 add      53     '<u>\t</u>int foo;<u class="cr"></u>\n'
 add      54     '<u>\t</u>int bar; <u class="cr"></u>\n'
 add      55     '<u>\t</u>int baz;<u>\t</u><u class="cr"></u>\n'
 add      56     '<u>\t</u>int space; <i></i>'
-add      57     '<u>\t</u>int tab;<u>\t</u>\n'
-add      58     '<u>\t</u>\n'
+add      57     '<u>\t</u>int tab;<u>\t</u><i></i>'
+add      58     '<u>\t</u><i></i>'
 unmod    59  53 ' <i></i>'
 del          54 '<u>\t</u>#define MAX_STEPS (48)\n'
 add      60     '<u>\t</u><u class="cr"></u>\n'