# HG changeset patch # User Mads Kiilerich # Date 1433883020 -7200 # Node ID c417ef1f43b16b980069b322b659b5a5e979536b # Parent 18b0e4d1ae589e4207ea119d97132c587430b33c diffs: avoid conflicts between inline diff mechanism and special markup It would sometimes emit markup like
 class="cr">
instead of
diff -r 18b0e4d1ae58 -r c417ef1f43b1 kallithea/lib/diffs.py --- a/kallithea/lib/diffs.py Tue Jun 09 22:50:20 2015 +0200 +++ b/kallithea/lib/diffs.py Tue Jun 09 22:50:20 2015 +0200 @@ -193,8 +193,8 @@ (?:^\+\+\+[ ](b/(?P.+?)|/dev/null)\t?(?:\n|$))? """, re.VERBOSE | re.MULTILINE) - #used for inline highlighter word split - _token_re = re.compile(r'()(>|<|&|\t| |\W+?)') + # Used for inline highlighter word split, must match the substitutions in _escaper + _token_re = re.compile(r'()(&|<|>|\t|| |\W+?)') _escape_re = re.compile(r'(&)|(<)|(>)|(\t)|(\r)|(?<=.)( \n| $)') diff -r 18b0e4d1ae58 -r c417ef1f43b1 kallithea/tests/fixtures/markuptest.diff --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kallithea/tests/fixtures/markuptest.diff Tue Jun 09 22:50:20 2015 +0200 @@ -0,0 +1,17 @@ +diff --git a/f b/f +--- a/f ++++ b/f +@@ -51,5 +51,12 @@ + begin(); + ++ int foo; ++ int bar; ++ int baz; ++ int space; ++ int tab; ++ + +- #define MAX_STEPS (48) ++ ++ #define MAX_STEPS (64) + diff -r 18b0e4d1ae58 -r c417ef1f43b1 kallithea/tests/models/test_diff_parsers.py --- a/kallithea/tests/models/test_diff_parsers.py Tue Jun 09 22:50:20 2015 +0200 +++ b/kallithea/tests/models/test_diff_parsers.py Tue Jun 09 22:50:20 2015 +0200 @@ -275,3 +275,32 @@ data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d] expected_data = DIFF_FIXTURES[diff_fixture] self.assertListEqual(expected_data, data) + + def test_diff_markup(self): + diff = fixture.load_resource('markuptest.diff', strip=False) + diff_proc = DiffProcessor(diff) + diff_proc_d = diff_proc.prepare() + chunks = diff_proc_d[0]['chunks'] + self.assertFalse(chunks[0]) + #from pprint import pprint; pprint(chunks[1]) + l = ['\n'] + for d in chunks[1]: + l.append('%(action)-7s %(new_lineno)3s %(old_lineno)3s %(line)r\n' % d) + s = ''.join(l) + print s + self.assertEqual(s, r''' +context ... ... u'@@ -51,5 +51,12 @@\n' +unmod 51 51 u'\tbegin();\n' +unmod 52 52 u'\t\n' +add 53 u'\tint foo;\n' +add 54 u'\tint bar; \n' +add 55 u'\tint baz;\t\n' +add 56 u'\tint space; ' +add 57 u'\tint tab;\t\n' +add 58 u'\t\n' +unmod 59 53 u' ' +del 54 u'\t#define MAX_STEPS (48)\n' +add 60 u'\t\n' +add 61 u'\t#define MAX_STEPS (64)\n' +unmod 62 55 u'\n' +''')