Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6153201

Browse files
committed
SF bug #1347874; FeedParser does not comply with RFC2822.
Change headerRE as suggested in the bug report, so that single character headers are accepted. Test case added too. Will backport to Python 2.4.
1 parent 20bad74 commit 6153201

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lib/email/FeedParser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2004 Python Software Foundation
1+
# Copyright (C) 2004-2006 Python Software Foundation
22
# Authors: Baxter, Wouters and Warsaw
33
44

@@ -29,7 +29,7 @@
2929
NLCRE_crack = re.compile('(\r\n|\r|\n)')
3030
# RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character
3131
# except controls, SP, and ":".
32-
headerRE = re.compile(r'^(From |[\041-\071\073-\176]{2,}:|[\t ])')
32+
headerRE = re.compile(r'^(From |[\041-\071\073-\176]{1,}:|[\t ])')
3333
EMPTYSTRING = ''
3434
NL = '\n'
3535

Lib/email/test/test_email.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,15 @@ def test_rfc2822_space_not_allowed_in_header(self):
24672467
msg = email.message_from_string(m)
24682468
eq(len(msg.keys()), 0)
24692469

2470+
def test_rfc2822_one_character_header(self):
2471+
eq = self.assertEqual
2472+
m = 'A: first header\nB: second header\nCC: third header\n\nbody'
2473+
msg = email.message_from_string(m)
2474+
headers = msg.keys()
2475+
headers.sort()
2476+
eq(headers, ['A', 'B', 'CC'])
2477+
eq(msg.get_payload(), 'body')
2478+
24702479

24712480

24722481
class TestBase64(unittest.TestCase):

0 commit comments

Comments
 (0)