forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpo-29412: Fix indexError when parsing a header value ending unexpect…
…edly (pythonGH-14387) * patched string index out of range error in get_word function of _header_value_parser.py and created tests in test__header_value_parser.py for CFWS. * Raise HeaderParseError instead of continuing when parsing a word.
- Loading branch information
Showing
3 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -930,6 +930,12 @@ def test_get_word_atom_yields_atom(self): | |
self.assertEqual(word.token_type, 'atom') | ||
self.assertEqual(word[0].token_type, 'cfws') | ||
|
||
def test_get_word_all_CFWS(self): | ||
# bpo-29412: Test that we don't raise IndexError when parsing CFWS only | ||
# token. | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_word('(Recipients list suppressed') | ||
|
||
def test_get_word_qs_yields_qs(self): | ||
word = self._test_get_x(parser.get_word, | ||
'"bar " (bang) ah', '"bar " (bang) ', 'bar ', [], 'ah') | ||
|
@@ -2343,6 +2349,17 @@ def test_get_address_quoted_strings_in_atom_list(self): | |
|
||
# get_address_list | ||
|
||
def test_get_address_list_CFWS(self): | ||
address_list = self._test_get_x(parser.get_address_list, | ||
'(Recipient list suppressed)', | ||
'(Recipient list suppressed)', | ||
' ', | ||
[errors.ObsoleteHeaderDefect], # no content in address list | ||
'') | ||
self.assertEqual(address_list.token_type, 'address-list') | ||
self.assertEqual(len(address_list.mailboxes), 0) | ||
self.assertEqual(address_list.mailboxes, address_list.all_mailboxes) | ||
|
||
def test_get_address_list_mailboxes_simple(self): | ||
address_list = self._test_get_x(parser.get_address_list, | ||
'[email protected]', | ||
|
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2019-06-25-19-27-25.bpo-29412.n4Zqdh.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix IndexError in parsing a header value ending unexpectedly. Patch by Abhilash | ||
Raj. |