diff mbox series

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

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

Commit Message

Brandon Maier Oct. 27, 2024, 3:33 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 ++----
 1 file changed, 2 insertions(+), 4 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: