diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py --- a/kallithea/lib/diffs.py +++ b/kallithea/lib/diffs.py @@ -193,8 +193,8 @@ class DiffProcessor(object): (?:^\+\+\+[ ](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 --git a/kallithea/tests/fixtures/markuptest.diff b/kallithea/tests/fixtures/markuptest.diff new file mode 100644 --- /dev/null +++ b/kallithea/tests/fixtures/markuptest.diff @@ -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 --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 @@ -275,3 +275,32 @@ class DiffLibTest(BaseTestCase): 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' +''')