diff mbox

parser: allow words starting with "diff" at beginning of line

Message ID 1326539860-5023-1-git-send-email-stefanha@linux.vnet.ibm.com
State Accepted
Commit b76f7dd32ef83d55ace2f38ed84f5fc76e65e18e
Headers show

Commit Message

Stefan Hajnoczi Jan. 14, 2012, 11:17 a.m. UTC
The patch parser splits emails incorrectly when the comment contains a
line whose first word starts with "diff" (like "difficult" or
"different").

For a real-life example of an email that triggers this bug, see
http://patchwork.ozlabs.org/patch/135291/.

Fix the issue by checking for a space after "diff".  Add
DiffWordInCommentTest to the test suite.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 apps/patchwork/parser.py            |    2 +-
 apps/patchwork/tests/patchparser.py |    5 +++++
 2 files changed, 6 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/apps/patchwork/parser.py b/apps/patchwork/parser.py
index 2b5e9a0..f460566 100644
--- a/apps/patchwork/parser.py
+++ b/apps/patchwork/parser.py
@@ -68,7 +68,7 @@  def parse_patch(text):
         line += '\n'
 
         if state == 0:
-            if line.startswith('diff') or line.startswith('===') \
+            if line.startswith('diff ') or line.startswith('===') \
                     or line.startswith('Index: '):
                 state = 1
                 buf += line
diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index 3870dc8..06b4e54 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -121,6 +121,11 @@  class ListFooterTest(InlinePatchTest):
         (self.patch, self.comment) = find_content(self.project, email)
 
 
+class DiffWordInCommentTest(InlinePatchTest):
+    test_comment = 'Lines can start with words beginning in "diff"\n' + \
+                   'difficult\nDifferent'
+
+
 class UpdateCommentTest(InlinePatchTest):
     """ Test for '---\nUpdate: v2' style comments to patches. """
     patch_filename = '0001-add-line.patch'