[Python-checkins] r42083 - in python/trunk/Lib/email: FeedParser.py test/test_email.py

barry.warsaw python-checkins at python.org
Tue Jan 17 06:58:09 CET 2006


Author: barry.warsaw
Date: Tue Jan 17 06:58:08 2006
New Revision: 42083

Modified:
   python/trunk/Lib/email/FeedParser.py
   python/trunk/Lib/email/test/test_email.py
Log:
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.

Modified: python/trunk/Lib/email/FeedParser.py
==============================================================================
--- python/trunk/Lib/email/FeedParser.py	(original)
+++ python/trunk/Lib/email/FeedParser.py	Tue Jan 17 06:58:08 2006
@@ -1,4 +1,4 @@
-# Copyright (C) 2004 Python Software Foundation
+# Copyright (C) 2004-2006 Python Software Foundation
 # Authors: Baxter, Wouters and Warsaw
 # Contact: email-sig at python.org
 
@@ -29,7 +29,7 @@
 NLCRE_crack = re.compile('(\r\n|\r|\n)')
 # RFC 2822 $3.6.8 Optional fields.  ftext is %d33-57 / %d59-126, Any character
 # except controls, SP, and ":".
-headerRE = re.compile(r'^(From |[\041-\071\073-\176]{2,}:|[\t ])')
+headerRE = re.compile(r'^(From |[\041-\071\073-\176]{1,}:|[\t ])')
 EMPTYSTRING = ''
 NL = '\n'
 

Modified: python/trunk/Lib/email/test/test_email.py
==============================================================================
--- python/trunk/Lib/email/test/test_email.py	(original)
+++ python/trunk/Lib/email/test/test_email.py	Tue Jan 17 06:58:08 2006
@@ -2467,6 +2467,15 @@
         msg = email.message_from_string(m)
         eq(len(msg.keys()), 0)
 
+    def test_rfc2822_one_character_header(self):
+        eq = self.assertEqual
+        m = 'A: first header\nB: second header\nCC: third header\n\nbody'
+        msg = email.message_from_string(m)
+        headers = msg.keys()
+        headers.sort()
+        eq(headers, ['A', 'B', 'CC'])
+        eq(msg.get_payload(), 'body')
+
 
 
 class TestBase64(unittest.TestCase):


More information about the Python-checkins mailing list