changeset 8701:84d2df525238

diff: polish _escaper function - clarify purpose and pass it strings
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 28 Oct 2020 16:08:04 +0100
parents 5332c632ac3f
children 8dce5e58eae3
files kallithea/lib/diffs.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Tue Oct 20 15:52:53 2020 +0200
+++ b/kallithea/lib/diffs.py	Wed Oct 28 16:08:04 2020 +0100
@@ -448,9 +448,9 @@
 _escape_re = re.compile(r'(&)|(<)|(>)|(\t)|(\r)|(?<=.)( \n| $)|(\t\n|\t$)')
 
 
-def _escaper(string):
+def _escaper(diff_line):
     """
-    Do HTML escaping/markup
+    Do HTML escaping/markup of a single diff line (including first +/- column)
     """
 
     def substitute(m):
@@ -471,7 +471,7 @@
             return '<u>\t</u><i></i>'
         assert False
 
-    return _escape_re.sub(substitute, safe_str(string))
+    return _escape_re.sub(substitute, diff_line)
 
 
 _git_header_re = re.compile(br"""
@@ -536,7 +536,7 @@
     rest = diff_chunk[match.end():]
     if rest and _header_next_check.match(rest):
         raise Exception('cannot parse %s diff header: %r followed by %r' % (vcs, safe_str(bytes(diff_chunk[:match.end()])), safe_str(bytes(rest[:1000]))))
-    diff_lines = (_escaper(m.group(0)) for m in re.finditer(br'.*\n|.+$', rest)) # don't split on \r as str.splitlines do
+    diff_lines = (_escaper(safe_str(m.group(0))) for m in re.finditer(br'.*\n|.+$', rest)) # don't split on \r as str.splitlines do
     return meta_info, diff_lines