Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/samples/sample_no_filename.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
+++
@@ -1,2 +1,2 @@
-foo
bar
+foobar
8 changes: 8 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,11 @@ def test_git_renaming(self):
# by unidiff are the same
with codecs.open(file_path, 'r', encoding='utf-8') as diff_file:
self.assertEqual(diff_file.read(), str(res))

def test_no_filename_in_header(self):
tests_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(tests_dir, 'samples/sample_no_filename.diff')
with codecs.open(file_path, 'r', encoding='utf-8') as diff_file:
res = PatchSet(diff_file)

self.assertEqual(' ', res.modified_files[0].source_file)
4 changes: 2 additions & 2 deletions unidiff/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@


RE_SOURCE_FILENAME = re.compile(
r'^--- (?P<filename>"?[^\t\n]+"?)(?:\t(?P<timestamp>[^\n]+))?')
r'^---( ?)(?P<filename>"?[^\t\n]+"?)(?:\t(?P<timestamp>[^\n]+))?')
RE_TARGET_FILENAME = re.compile(
r'^\+\+\+ (?P<filename>"?[^\t\n]+"?)(?:\t(?P<timestamp>[^\n]+))?')
r'^\+\+\+( ?)(?P<filename>"?[^\t\n]+"?)(?:\t(?P<timestamp>[^\n]+))?')


# check diff git line for git renamed files support
Expand Down
2 changes: 1 addition & 1 deletion unidiff/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def _parse(
if is_hunk_header:
patch_info = None
if current_file is None:
raise UnidiffParseError('Unexpected hunk found: {line}')
raise UnidiffParseError(f'Unexpected hunk found: {line}')
current_file._parse_hunk(
line,
enumerated_diff,
Expand Down