From: epriestley Date: Mon, 22 Oct 2012 18:15:36 +0000 (-0700) Subject: Fix some regexp issues for parsing SVN diffs with \r\n newlines X-Git-Tag: conduit-6~63 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=10653d7ff37834debfa62b6f4b372c7914328c01;p=arcanist.git Fix some regexp issues for parsing SVN diffs with \r\n newlines Summary: We need to tweak a few patterns to accommodate the possibility that lines end in "\r\n". Test Plan: Added failing unit test and made it pass. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran, mbishopim3 Maniphest Tasks: T1944 Differential Revision: https://secure.phabricator.com/D3772 --- diff --git a/src/parser/ArcanistDiffParser.php b/src/parser/ArcanistDiffParser.php index 188e6d4b..ee55d721 100644 --- a/src/parser/ArcanistDiffParser.php +++ b/src/parser/ArcanistDiffParser.php @@ -649,7 +649,7 @@ final class ArcanistDiffParser { $line = $this->getLine(); if ($is_svn) { - $ok = preg_match('/^=+$/', $line); + $ok = preg_match('/^=+\s*$/', $line); if (!$ok) { $this->didFailParse("Expected '=======================' divider line."); } else { @@ -684,8 +684,8 @@ final class ArcanistDiffParser { } $is_binary_add = preg_match( - '/^Cannot display: file marked as a binary type.$/', - $line); + '/^Cannot display: file marked as a binary type\.$/', + rtrim($line)); if ($is_binary_add) { $this->nextLine(); // Cannot display: file marked as a binary type. $this->nextNonemptyLine(); // svn:mime-type = application/octet-stream @@ -697,7 +697,7 @@ final class ArcanistDiffParser { // WITHOUT a binary mime-type and is changed and given a binary mime-type. $is_binary_diff = preg_match( '/^Binary files .* and .* differ$/', - $line); + rtrim($line)); if ($is_binary_diff) { $this->nextNonemptyLine(); // Binary files x and y differ $this->markBinary($change); @@ -710,7 +710,7 @@ final class ArcanistDiffParser { // can not apply these patches.) $is_hg_binary_delete = preg_match( '/^Binary file .* has changed$/', - $line); + rtrim($line)); if ($is_hg_binary_delete) { $this->nextNonemptyLine(); $this->markBinary($change); @@ -723,7 +723,7 @@ final class ArcanistDiffParser { // patch. $is_git_binary_patch = preg_match( '/^GIT binary patch$/', - $line); + rtrim($line)); if ($is_git_binary_patch) { $this->nextLine(); $this->parseGitBinaryPatch(); @@ -739,7 +739,7 @@ final class ArcanistDiffParser { if ($is_git) { // "git diff -b" ignores whitespace, but has an empty hunk target - if (preg_match('@^diff --git a/.*$@', $line)) { + if (preg_match('@^diff --git .*$@', $line)) { $this->nextLine(); return null; } diff --git a/src/parser/__tests__/ArcanistDiffParserTestCase.php b/src/parser/__tests__/ArcanistDiffParserTestCase.php index e59a2df5..e4c4c3e8 100644 --- a/src/parser/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/__tests__/ArcanistDiffParserTestCase.php @@ -549,6 +549,9 @@ EOTEXT 'dst/file', $change->getCurrentPath()); break; + case 'more-newlines.svndiff': + $this->assertEqual(1, count($changes)); + break; default: throw new Exception("No test block for diff file {$diff_file}."); break; diff --git a/src/parser/__tests__/diff/more-newlines.svndiff b/src/parser/__tests__/diff/more-newlines.svndiff new file mode 100644 index 00000000..ce40e70a --- /dev/null +++ b/src/parser/__tests__/diff/more-newlines.svndiff @@ -0,0 +1,13 @@ +Index: Database/tables/dbo.Account.sql +=================================================================== +--- Database/tables/dbo.Account.sql (revision 1587) ++++ Database/tables/dbo.Account.sql (working copy) +@@ -23,6 +23,8 @@ + GO + CREATE CLUSTERED INDEX IX_Account ON [Account] ([CreationDateTime]) + GO ++ALTER TABLE [dbo].[Account] ADD CONSTRAINT [UK_Account_APIKey] UNIQUE ([APIKey]) ++GO + ALTER TABLE [dbo].[Account] ADD CONSTRAINT [DF_Account_AccountId] DEFAULT (newid()) FOR [AccountId] + GO + ALTER TABLE [dbo].[Account] ADD CONSTRAINT [DF_Account_CreationDateTime] DEFAULT (getutcdate()) FOR [CreationDateTime]