diff mbox series

[b4,v2,5/6] b4: handle trailers with special characters

Message ID 20241027-trailer-special-chars-v2-5-e963f78b3ef8@gmail.com (mailing list archive)
State New
Headers show
Series Handle patch trailers with special characters | expand

Commit Message

Brandon Maier Oct. 27, 2024, 10:34 p.m. UTC
Parsing an email trailer with special characters breaks the formatting.
For example this trailer.

> Reviewed-by: "Doe, Jane" <jane@example.com>

Will get parsed into this.

> Reviewed-by: Doe, Jane <jane@example.com>

This is because b4.LoreTrailer attempts to reformat the trailer using a
naive string format. Instead use the Python standard library formataddr
function which correctly handles special characters.

Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
---
 src/b4/__init__.py                                                | 6 ++----
 src/tests/samples/trailers-followup-bare-address-ref-defaults.txt | 2 +-
 src/tests/samples/trailers-followup-name-parens-ref-defaults.txt  | 2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index cf112e3bce2911c78cff18aac267608f796957ab..0785be8ffcef08fb5cd4c484a40e6fe856446cfe 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -1061,10 +1061,8 @@  def __init__(self, name: Optional[str] = None, value: Optional[str] = None, exti
                 self.type = 'person'
                 self.addr = email.utils.parseaddr(value)
                 # Normalize the value with parsed data
-                if self.addr[0]:
-                    self.value = f'{self.addr[0]} <{self.addr[1]}>'
-                elif self.addr[1]:
-                    self.value = self.addr[1]
+                if self.addr[0] or self.addr[1]:
+                    self.value = email.utils.formataddr(self.addr)
                 else:
                     self.type = 'unknown'
             else:
diff --git a/src/tests/samples/trailers-followup-bare-address-ref-defaults.txt b/src/tests/samples/trailers-followup-bare-address-ref-defaults.txt
index 7b1ebef3c9d9b9c60288dc07bcf7f82f066c6934..82e1576019bd9f4d69f9a2ed9b783340a5ea16b2 100644
--- a/src/tests/samples/trailers-followup-bare-address-ref-defaults.txt
+++ b/src/tests/samples/trailers-followup-bare-address-ref-defaults.txt
@@ -14,7 +14,7 @@  Cc: bare-address@example.org
 Reviewed-by: Original Reviewer <original-reviewer@example.com>
 Link: https://msgid.link/some@msgid.here
 Signed-off-by: Original Submitter <original-submitter@example.com>
-Reviewed-by: Followup Reviewer1 (corporate) <followup-reviewer1@example.com>
+Reviewed-by: "Followup Reviewer1 (corporate)" <followup-reviewer1@example.com>
 Tested-by: Followup Reviewer2 <followup-reviewer2@example.com>
 
 diff --git a/b4/junk.py b/b4/junk.py
diff --git a/src/tests/samples/trailers-followup-name-parens-ref-defaults.txt b/src/tests/samples/trailers-followup-name-parens-ref-defaults.txt
index 06b883126bd3ea9f7a4d22c58fc10e9e89d6bde7..dfc013c89c415107ff2517c1715e523982df2afc 100644
--- a/src/tests/samples/trailers-followup-name-parens-ref-defaults.txt
+++ b/src/tests/samples/trailers-followup-name-parens-ref-defaults.txt
@@ -13,7 +13,7 @@  Fixes: abcdef01234567890
 Reviewed-by: Original Reviewer <original-reviewer@example.com>
 Link: https://msgid.link/some@msgid.here
 Signed-off-by: Original Submitter <original-submitter@example.com>
-Reviewed-by: Followup Reviewer1 (corporate) <followup-reviewer1@example.com>
+Reviewed-by: "Followup Reviewer1 (corporate)" <followup-reviewer1@example.com>
 Tested-by: Followup Reviewer2 <followup-reviewer2@example.com>
 
 diff --git a/b4/junk.py b/b4/junk.py