Skip to content

Commit 660ee12

Browse files
test(smtplib): Add tests for quoteaddr angle-bracket handling
Add testQuoteAddr for basic quoteaddr behavior and testQuoteAddrMalformedAngleBracket for inputs starting with '<' but missing closing '>'. The latter fails without the fix.
1 parent fc8b6c8 commit 660ee12

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/test/test_smtplib.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ def testQuoteData(self):
7777
expected = "abc\r\n..jkl\r\nfoo\r\n...blue"
7878
self.assertEqual(expected, smtplib.quotedata(teststr))
7979

80+
def testQuoteAddr(self):
81+
# Standard address is wrapped in angle brackets.
82+
self.assertEqual(smtplib.quoteaddr('user@example.com'),
83+
'<user@example.com>')
84+
# Already angle-bracketed and valid.
85+
self.assertEqual(smtplib.quoteaddr('<user@example.com>'),
86+
'<user@example.com>')
87+
# Empty string produces empty angle brackets.
88+
self.assertEqual(smtplib.quoteaddr(''), '<>')
89+
90+
def testQuoteAddrMalformedAngleBracket(self):
91+
# Inputs starting with '<' but missing closing '>' must still
92+
# produce output that ends with '>'.
93+
result = smtplib.quoteaddr('<')
94+
self.assertTrue(result.startswith('<') and result.endswith('>'), result)
95+
result = smtplib.quoteaddr('< ')
96+
self.assertTrue(result.startswith('<') and result.endswith('>'), result)
97+
result = smtplib.quoteaddr('<user@example.com')
98+
self.assertTrue(result.startswith('<') and result.endswith('>'), result)
99+
80100
def testBasic1(self):
81101
mock_socket.reply_with(b"220 Hola mundo")
82102
# connects

0 commit comments

Comments
 (0)