Skip to content

Commit 21913c2

Browse files
Julia WangJulia Wang
authored andcommitted
Allow quotations around filenames
Recently, I ran into a bug in which a line containing an unusual character was not parsed correctly by this gem. By inspecting the diff, I discovered that it was because `git` adds quotations around pathnames containing unusual characters (see https://git-scm.com/docs/git-config#git-config-corequotePath). The line in question looked like the following: ``` --- "a/app/foo/bar/FOO\357\234\202REVIEWERS" ``` This pull request changes the diff metadata regular expressions to allow for such quoted strings.
1 parent 70627f5 commit 21913c2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/git_diff/file.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ def append_to_current_hunk(string)
5454
def extract_diff_meta_data(string)
5555
if a_path_info = %r{^[-]{3} /dev/null(.*)$}.match(string)
5656
@a_path = "/dev/null"
57-
elsif a_path_info = %r{^[-]{3} a/(.*)$}.match(string)
57+
elsif a_path_info = %r{^[-]{3} "?a/(.*)$}.match(string)
5858
@a_path = a_path_info[1]
5959
elsif b_path_info = %r{^[+]{3} /dev/null(.*)$}.match(string)
6060
@b_path = "/dev/null"
61-
elsif b_path_info = %r{^[+]{3} b/(.*)$}.match(string)
61+
elsif b_path_info = %r{^[+]{3} "?b/(.*)$}.match(string)
6262
@b_path = b_path_info[1]
6363
elsif blob_info = /^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$/.match(string)
6464
@a_blob, @b_blob, @b_mode = *blob_info.captures
@@ -78,7 +78,7 @@ def extract_diff_meta_data(string)
7878
else
7979
@b_path = copy_rename_info.captures[2]
8080
end
81-
elsif binary_info = %r{^Binary files (?:/dev/null|a/(.*)) and (?:/dev/null|b/(.*)) differ$}.match(string)
81+
elsif binary_info = %r{^Binary files (?:/dev/null|"?a/(.*)) and (?:/dev/null|"?b/(.*)) differ$}.match(string)
8282
@binary = true
8383
@a_path ||= binary_info[1] || "/dev/null"
8484
@b_path ||= binary_info[2] || "/dev/null"

0 commit comments

Comments
 (0)