When checking a patch file, the author is taken from the 'From:' header
of the mail as is, while the Signed-off-by tags are plain text in the
body.  git format-patch quotes a display name with special characters,
such as a '.', and RFC 2047 encodes a non-ASCII one, so such an author
never matches its own sign-off, resulting in a false positive error:

 == Checking "patch.mbox" ==
 ERROR: Author "Aeliton G. Silva" <[email protected]> needs to sign 
off.
 Lines checked: 285, Warnings: 0, Errors: 1

The same happens to a non-ASCII name:

 ERROR: Author =?UTF-8?q?Jo=C3=A3o=20Silva?= <[email protected]> needs to sign 
off.

Fix that by decoding and unquoting the display name of the author before
the comparison.  This doesn't affect checking the git commits with -N,
where the author is formatted as plain '%an <%ae>'.

Fixes: 3267343a8487 ("checkpatch: Improve accuracy and specificity of sign-off 
checking.")
Signed-off-by: Aeliton G. Silva <[email protected]>
Assisted-by: Claude Opus 5.5, Claude Code
---
 tests/checkpatch.at     | 16 ++++++++++++++++
 utilities/checkpatch.py | 22 ++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/tests/checkpatch.at b/tests/checkpatch.at
index 249f0f066..73df4e333 100755
--- a/tests/checkpatch.at
+++ b/tests/checkpatch.at
@@ -215,6 +215,22 @@ try_checkpatch \
     Signed-off-by: A" \
    "ERROR: Patch lacks author."
 
+# A mail header quotes a display name with special characters and RFC 2047
+# encodes a non-ASCII one, while the sign-off carries the plain name.
+try_checkpatch \
+   "From: \"A. B\" <[email protected]>
+
+    Signed-off-by: A. B <[email protected]>"
+try_checkpatch \
+   "From: =?UTF-8?q?Jo=C3=A3o?= <[email protected]>
+
+    Signed-off-by: João <[email protected]>"
+try_checkpatch \
+   "From: \"A. B\" <[email protected]>
+
+    Signed-off-by: C <[email protected]>" \
+   "ERROR: Author A. B <[email protected]> needs to sign off."
+
 AT_CLEANUP
 
 
diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 653ae3315..bfe244076 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -15,6 +15,8 @@
 # limitations under the License.
 
 import email
+import email.header
+import email.utils
 import getopt
 import os
 import re
@@ -895,6 +897,21 @@ def do_authors_exist(authors):
     return missing_authors
 
 
+def normalize_author(author):
+    # A mail header quotes a display name with special characters, such
+    # as a '.', and RFC 2047 encodes a non-ASCII one, while Signed-off-by
+    # tags carry the plain name.  Decode and unquote the name, so the
+    # author can be compared with the tags.
+    if not author or '<' not in author:
+        return author
+    decoded = str(email.header.make_header(
+        email.header.decode_header(author)))
+    name, address = email.utils.parseaddr(decoded)
+    if not name or not address:
+        return author
+    return '%s <%s>' % (name, address)
+
+
 def ovs_checkpatch_parse(text, filename, author=None, committer=None):
     global print_file_name, total_line, checking_file, \
         empty_return_check_state, missing_authors
@@ -1020,7 +1037,7 @@ def ovs_checkpatch_parse(text, filename, author=None, 
committer=None):
             elif is_committer.match(line):
                 committer = is_committer.match(line).group(2)
             elif is_author.match(line):
-                author = is_author.match(line).group(2)
+                author = normalize_author(is_author.match(line).group(2))
             elif is_subject.match(line):
                 run_subject_checks(line, spellcheck)
             elif is_signature.match(line):
@@ -1151,7 +1168,8 @@ def ovs_checkpatch_file(filename):
         if part.get_content_maintype() == 'multipart':
             continue
     result = ovs_checkpatch_parse(part.get_payload(decode=False), filename,
-                                  mail.get('Author', mail['From']),
+                                  normalize_author(
+                                      mail.get('Author', mail['From'])),
                                   mail['Commit'])
 
     if not mail['Subject'] or not mail['Subject'].strip():

base-commit: 000c7330c1c98aae7e4a870eee8f2db6a6fa1d97
-- 
2.43.0


-- 




_‘Esta mensagem é direcionada apenas para os endereços constantes no 
cabeçalho inicial. Se você não está listado nos endereços constantes no 
cabeçalho, pedimos-lhe que desconsidere completamente o conteúdo dessa 
mensagem e cuja cópia, encaminhamento e/ou execução das ações citadas estão 
imediatamente anuladas e proibidas’._


* **‘Apesar do Magazine Luiza tomar 
todas as precauções razoáveis para assegurar que nenhum vírus esteja 
presente nesse e-mail, a empresa não poderá aceitar a responsabilidade por 
quaisquer perdas ou danos causados por esse e-mail ou por seus anexos’.*



_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to