diff --git a/parso/python/diff.py b/parso/python/diff.py index 41f1794..8eb31b4 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -388,8 +388,10 @@ class DiffParser(object): # endmarker or another dedented code block. typ, string, start_pos, prefix = next(tokens) if '\n' in prefix or '\r' in prefix: - prefix = re.sub(r'(?<=\n|\r)[^\n\r]+$', '', prefix) + prefix = re.sub(r'[^\n\r]+\Z', '', prefix) else: + # This is basically the next line and it still needs to + # be parserd. prefix = '' yield PythonToken( PythonTokenTypes.ENDMARKER, '', diff --git a/test/test_diff_parser.py b/test/test_diff_parser.py index 5946f8d..2746dc1 100644 --- a/test/test_diff_parser.py +++ b/test/test_diff_parser.py @@ -955,6 +955,10 @@ def test_wrong_backslash(differ): differ.parse(code1, parsers=1, copies=1) +def test_comment_change(differ): + differ.initialize('') + + def test_random_unicode_characters(differ): """ Those issues were all found with the fuzzer. @@ -970,3 +974,4 @@ def test_random_unicode_characters(differ): differ.parse(s + '\n', parsers=1, expect_error_leaves=True) differ.parse(' result = (\r\f\x17\t\x11res)', parsers=2, expect_error_leaves=True) differ.parse('') + differ.parse(' a( # xx\ndef', parsers=2, expect_error_leaves=True)