From 65b6e1bdac6eea20d10e802bbe42abb4e82a6790 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 14 Aug 2014 12:13:02 -0700 Subject: [PATCH] Don't parse separator tabs as part of the filename in Git diffs which affect files with spaces Summary: Fixes T5870. When a filename contains spaces, Git will add a "\t" at the end of the "---" and "+++" lines. We currently consume this and think we're reading a file called "blah blah\t". Instead, parse it out as not part of the filename. Test Plan: Added failing unit test and made it pass. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5870 Differential Revision: https://secure.phabricator.com/D10267 --- src/parser/ArcanistDiffParser.php | 4 ++++ src/parser/__tests__/ArcanistDiffParserTestCase.php | 6 ++++++ src/parser/__tests__/diff/git-remove-spaces.gitdiff | 11 +++++++++++ 3 files changed, 21 insertions(+) create mode 100644 src/parser/__tests__/diff/git-remove-spaces.gitdiff diff --git a/src/parser/ArcanistDiffParser.php b/src/parser/ArcanistDiffParser.php index 50d9c3bd..658601c3 100644 --- a/src/parser/ArcanistDiffParser.php +++ b/src/parser/ArcanistDiffParser.php @@ -830,6 +830,10 @@ final class ArcanistDiffParser { $remainder = '\t.*'; } else if ($this->isRCS) { $remainder = '\s.*'; + } else if ($this->getIsGit()) { + // When filenames contain spaces, Git terminates this line with a tab. + // Normally, the tab is not present. If there's a tab, ignore it. + $remainder = '(?:\t.*)?'; } $ok = preg_match( diff --git a/src/parser/__tests__/ArcanistDiffParserTestCase.php b/src/parser/__tests__/ArcanistDiffParserTestCase.php index 8e547a6e..37801315 100644 --- a/src/parser/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/__tests__/ArcanistDiffParserTestCase.php @@ -595,6 +595,12 @@ EOTEXT $hunks = $change->getHunks(); $this->assertEqual(1, count($hunks)); break; + case 'git-remove-spaces.gitdiff': + $this->assertEqual(1, count($changes)); + + $change = array_shift($changes); + $this->assertEqual('file with spaces.txt', $change->getOldPath()); + break; default: throw new Exception("No test block for diff file {$diff_file}."); break; diff --git a/src/parser/__tests__/diff/git-remove-spaces.gitdiff b/src/parser/__tests__/diff/git-remove-spaces.gitdiff new file mode 100644 index 00000000..a0723ab9 --- /dev/null +++ b/src/parser/__tests__/diff/git-remove-spaces.gitdiff @@ -0,0 +1,11 @@ +diff --git a/file with spaces.txt b/file with spaces.txt +deleted file mode 100644 +index ae9854d..0000000 +--- a/file with spaces.txt ++++ /dev/null +@@ -1,5 +0,0 @@ +-duck +-duck +-duck +-duck +-goose -- 2.43.0