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 <d...@axtens.net> --- patchwork/parser.py | 7 ++++++- patchwork/tests/test_parser.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/patchwork/parser.py b/patchwork/parser.py index 8b3a712905b9..2cabb3cbc299 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -428,7 +428,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))) diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index b7bf224cede0..20d70af12120 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -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) -- 2.14.1 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork