signatures.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
To: signatures@kernel.org
Subject: [PATCH 05/10] Tighten follow-up header parsing
Date: Fri,  2 Oct 2020 19:29:10 -0400	[thread overview]
Message-ID: <20201002232915.1728301-6-konstantin@linuxfoundation.org> (raw)
In-Reply-To: <20201002232915.1728301-1-konstantin@linuxfoundation.org>

The combined routine was too broad for parsing follow-up messages, so
this tightens it to avoid too many false positive matches.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
---
 b4/__init__.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/b4/__init__.py b/b4/__init__.py
index 1cebe2b..d4a67a5 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1179,6 +1179,8 @@ class LoreMessage:
 
     @staticmethod
     def find_trailers(body):
+        headers = ('subject', 'date', 'from')
+        nonperson = ('fixes', 'subject', 'date')
         # Fix some more common copypasta trailer wrapping
         # Fixes: abcd0123 (foo bar
         # baz quux)
@@ -1189,7 +1191,8 @@ class LoreMessage:
         # Signed-off-by: Foo foo <foo@foo.com>
         # [for the thing that the thing is too long the thing that is
         # thing but thing]
-        body = re.sub(r'^(\[[^]]+)\n([^]]+]$)', r'\1 \2', body, flags=re.M)
+        # (too false-positivey, commented out)
+        # body = re.sub(r'^(\[[^]]+)\n([^]]+]$)', r'\1 \2', body, flags=re.M)
         trailers = list()
         others = list()
         was_trailer = False
@@ -1197,8 +1200,17 @@ class LoreMessage:
             line = line.strip('\r')
             matches = re.search(r'^(\w\S+):\s+(\S.*)', line, flags=re.I)
             if matches:
-                was_trailer = True
                 groups = list(matches.groups())
+                # We only accept headers if we haven't seen any non-trailer lines
+                tname = groups[0].lower()
+                if len(others) and tname in headers:
+                    logger.debug('Ignoring %s (header after other content)', line)
+                    continue
+                mperson = re.search(r'<[^>]+>', groups[1])
+                if not mperson and tname not in nonperson:
+                    logger.debug('Ignoring %s (not a recognized non-person trailer)', line)
+                    continue
+                was_trailer = True
                 groups.append(None)
                 trailers.append(groups)
                 continue
-- 
2.26.2



  parent reply	other threads:[~2020-10-02 23:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02 23:29 [PATCH 00/10] Entirely fake patch set Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 01/10] Use shorter cache file names Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 02/10] Preserve trailer order by default Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 03/10] Don't force trailers into a set Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 04/10] Initial go at supporting [extra trailer data] Konstantin Ryabitsev
2020-10-02 23:29 ` Konstantin Ryabitsev [this message]
2020-10-02 23:29 ` [PATCH 06/10] Use a more precise regex for email trailers Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 07/10] Set charset in order to generate MIME headers Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 08/10] Use bytes when dumping to stdout Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 09/10] Don't crash when no valid patches are found Konstantin Ryabitsev
2020-10-02 23:29 ` [PATCH 10/10] Fix some cherry-picking corner cases Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201002232915.1728301-6-konstantin@linuxfoundation.org \
    --to=konstantin@linuxfoundation.org \
    --cc=signatures@kernel.org \
    --subject='Re: [PATCH 05/10] Tighten follow-up header parsing' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox