Skip to content

Commit a840305

Browse files
authored
Merge pull request #100 from dleen/master
Fix issue with spaces in filename when using custom prefix
2 parents 3de381b + 9679b10 commit a840305

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diff --git src://foo bar/baz dst://foo bar/baz
2+
new file mode 100644
3+
index 00000000000..0a72e5064c8
4+
--- /dev/null
5+
+++ dst://foo bar/baz
6+
@@ -0,0 +1,1 @@
7+
+blah

tests/test_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ def test_parse_filename_with_spaces(self):
325325
self.assertTrue(res[0].is_added_file)
326326
self.assertEqual(res[0].path, 'has spaces/t.sql')
327327

328+
def test_parse_filename_prefix_with_spaces(self):
329+
filename = os.path.join(self.samples_dir, 'samples/git_filenames_with_spaces_prefix.diff')
330+
with open(filename) as f:
331+
res = PatchSet(f)
332+
333+
self.assertEqual(len(res), 1)
334+
335+
self.assertEqual(res[0].source_file, '/dev/null')
336+
self.assertEqual(res[0].target_file, 'dst://foo bar/baz')
337+
self.assertTrue(res[0].is_added_file)
338+
self.assertEqual(res[0].path, 'dst://foo bar/baz')
339+
328340
def test_deleted_file(self):
329341
filename = os.path.join(self.samples_dir, 'samples/git_delete.diff')
330342
with open(filename) as f:

unidiff/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
# check diff git line for git renamed files support
3939
RE_DIFF_GIT_HEADER = re.compile(
4040
r'^diff --git (?P<source>a/[^\t\n]+) (?P<target>b/[^\t\n]+)')
41+
RE_DIFF_GIT_HEADER_URI_LIKE = re.compile(
42+
r'^diff --git (?P<source>.*://[^\t\n]+) (?P<target>.*://[^\t\n]+)')
4143
RE_DIFF_GIT_HEADER_NO_PREFIX = re.compile(
4244
r'^diff --git (?P<source>[^\t\n]+) (?P<target>[^\t\n]+)')
4345

unidiff/patch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
LINE_VALUE_NO_NEWLINE,
4141
RE_DIFF_GIT_DELETED_FILE,
4242
RE_DIFF_GIT_HEADER,
43+
RE_DIFF_GIT_HEADER_URI_LIKE,
4344
RE_DIFF_GIT_HEADER_NO_PREFIX,
4445
RE_DIFF_GIT_NEW_FILE,
4546
RE_HUNK_BODY_LINE,
@@ -479,7 +480,9 @@ def _parse(self, diff, encoding, metadata_only):
479480
line = line.decode(encoding)
480481

481482
# check for a git file rename
482-
is_diff_git_header = RE_DIFF_GIT_HEADER.match(line) or RE_DIFF_GIT_HEADER_NO_PREFIX.match(line)
483+
is_diff_git_header = RE_DIFF_GIT_HEADER.match(line) or \
484+
RE_DIFF_GIT_HEADER_URI_LIKE.match(line) or \
485+
RE_DIFF_GIT_HEADER_NO_PREFIX.match(line)
483486
if is_diff_git_header:
484487
patch_info = PatchInfo()
485488
source_file = is_diff_git_header.group('source')

0 commit comments

Comments
 (0)