Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid existing quotes
  • Loading branch information
ecarreras committed Jul 30, 2025
commit 1be86f870f9b9d530efd5eb1eb9c99f3d862e0f4
4 changes: 3 additions & 1 deletion qreu/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def normalize_display_address(addr_string):
email = addr_part.strip('> ').strip()

if name and not (name.startswith('"') and name.endswith('"')):
name = '"{}"'.format(name)
name = name.replace('"', r'\"')
if any(c in name for c in [',', ';', ':']):
name = '"{}"'.format(name)

return '{} <{}>'.format(name, email)
return addr_string # If no angle brackets found, return as-is
Expand Down
6 changes: 6 additions & 0 deletions spec/address_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@
addr_str = 'Admin Name admin@example.com'
normalized = normalize_display_address(addr_str)
expect(normalized).to(equal(addr_str))

with it('must escape internal quotes if present'):
addr_str = 'SAYS "YES", PEPITA <pepita@example.com>'
expect(normalize_display_address(addr_str)).to(equal(
u'"SAYS \\"YES\\", PEPITA" <pepita@example.com>'
))