]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parser: Correct empty email value check
authorStephen Finucane <stephen.finucane@intel.com>
Mon, 18 Apr 2016 10:21:09 +0000 (11:21 +0100)
committerStephen Finucane <stephenfinucane@hotmail.com>
Fri, 2 Sep 2016 19:04:14 +0000 (20:04 +0100)
The check for empty emails in 'find_author' checked for None, but it
was not possible to ever return None unless the 'From:' header was
missing altogether. Seeing as, per RFC822 and its revisions, this is
not possible, check for the empty string instead.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/parser.py
patchwork/tests/test_parser.py

index cadfe74b7f1f2d9b307bc0b63b3161263e295d4c..1805df8cda7f5927dfd4e286dd9aead87e90f94d 100644 (file)
@@ -107,6 +107,8 @@ def find_author(mail):
     # tuple of (regex, fn)
     #  - where fn returns a (name, email) tuple from the match groups resulting
     #    from re.match().groups()
+    # TODO(stephenfin): Perhaps we should check for "real" email addresses
+    # instead of anything ('.*?')
     from_res = [
         # for "Firstname Lastname" <example@example.com> style addresses
         (re.compile(r'"?(.*?)"?\s*<([^>]+)>'), (lambda g: (g[0], g[1]))),
@@ -128,7 +130,7 @@ def find_author(mail):
             (name, email) = fn(match.groups())
             break
 
-    if email is None:
+    if not email:
         raise ValueError("Invalid 'From' header")
 
     email = email.strip()
index 3ca049bd6aa22841d23fcb8f107a1a98a0142566..7b5c71bbcee7b1e46466cc9d33d83b3ce23a4acc 100644 (file)
@@ -228,6 +228,11 @@ class SenderEncodingTest(TestCase):
         db_person = Person.objects.get(email=sender_email)
         self.assertEqual(person, db_person)
 
+    def test_empty(self):
+        email = self._create_email('')
+        with self.assertRaises(ValueError):
+            find_author(email)
+
     def test_ascii_encoding(self):
         from_header = 'example user <user@example.com>'
         sender_name = u'example user'