]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parser: allow series numbers at end of another prefix
authorDaniel Axtens <dja@axtens.net>
Mon, 29 Jan 2018 15:19:57 +0000 (02:19 +1100)
committerDaniel Axtens <dja@axtens.net>
Sat, 3 Feb 2018 03:11:15 +0000 (14:11 +1100)
We see some emails with e.g. "[PATCH1/8]" - no space between H and 1.

This is poor behaviour but we can accept it anyway.

Fixes: #126
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/parser.py
patchwork/tests/test_parser.py

index f99972ec9e20b25b17abd16a3a2494fbada1c25c..e0770bd92e1ab177335696743758e9389fa5e574 100644 (file)
@@ -425,7 +425,12 @@ def parse_series_marker(subject_prefixes):
         (x, n) if markers found, else (None, None)
     """
 
-    regex = re.compile(r'^([0-9]+)(?:/| of )([0-9]+)$')
+    # Allow for there to be stuff before the number. This allows for
+    # e.g. "PATCH1/8" which we have seen in the wild. To allow
+    # e.g. PATCH100/123 to work, make the pre-number match
+    # non-greedy. To allow really pathological cases like v2PATCH12/15
+    # to work, allow it to match everthing (don't exclude numbers).
+    regex = re.compile(r'.*?([0-9]+)(?:/| of )([0-9]+)$')
     m = _find_matching_prefix(subject_prefixes, regex)
     if m:
         return (int(m.group(1)), int(m.group(2)))
index 6422a8690c44b98d6d6adc53ea6da8d2e4268da5..f50f212280f810c0e54aead4ccc2a262601ace6b 100644 (file)
@@ -874,6 +874,16 @@ class SubjectTest(TestCase):
         self.assertEqual(parse_series_marker(['bar', '0/12']), (0, 12))
         self.assertEqual(parse_series_marker(['bar', '1 of 2']), (1, 2))
         self.assertEqual(parse_series_marker(['bar', '0 of 12']), (0, 12))
+        # Handle people missing the space between PATCH and the markers
+        # e.g. PATCH1/8
+        self.assertEqual(parse_series_marker(['PATCH1/8']), (1, 8))
+        self.assertEqual(parse_series_marker(['PATCH1 of 8']), (1, 8))
+        # verify the prefix-stripping is non-greedy
+        self.assertEqual(parse_series_marker(['PATCH100/123']), (100, 123))
+        # and that it is hard to confuse
+        self.assertEqual(parse_series_marker(['v2PATCH1/4']), (1, 4))
+        self.assertEqual(parse_series_marker(['v2', 'PATCH1/4']), (1, 4))
+        self.assertEqual(parse_series_marker(['v2.3PATCH1/4']), (1, 4))
 
     def test_version(self):
         self.assertEqual(parse_version('', []), 1)