-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String index out of range in get_group(), email/_header_value_parser.py #77657
Comments
When address group is missing final ';', 'value' will be an empty string. I suggest the following patch $ diff -u _save_header_value_parser.py _header_value_parser.py
--- _save_header_value_parser.py 2018-03-14 01:07:54.000000000 +0100
+++ _header_value_parser.py 2018-05-13 02:17:13.830053600 +0200
@@ -1876,7 +1876,7 @@
if not value:
group.defects.append(errors.InvalidHeaderDefect(
"end of header in group"))
- if value[0] != ';':
+ elif value[0] != ';':
raise errors.HeaderParseError(
"expected ';' at end of group but found {}".format(value))
group.append(ValueTerminal(';', 'group-terminator')) |
The fix is mostly likely correct, so we need a PR for this that includes tests. |
Unsure how to issue a "PR" (Problem Report?) with a test case. Here is my best effort: Create a file "email.eml" in the current directory, as attached. Then run the following test program (It appears that I can only attach one file to this ). $ cat test-bug.py
from email.policy import default
import email with open('email.eml', 'rb') as f:
msg = email.message_from_binary_file(f, policy=default)
toheader = msg['To']
for addr in toheader.addresses:
print(addr) #---------------------------------------------------- $ python3.6.5 test-bug.py
Traceback (most recent call last):
File "test-bug.py", line 6, in <module>
toheader = msg['To']
File "C:\Program Files\Python36\lib\email\message.py", line 391, in __getitem__
return self.get(name)
File "C:\Program Files\Python36\lib\email\message.py", line 471, in get
return self.policy.header_fetch_parse(k, v)
File "C:\Program Files\Python36\lib\email\policy.py", line 162, in header_fetch_parse
return self.header_factory(name, value)
File "C:\Program Files\Python36\lib\email\headerregistry.py", line 589, in __call__
return self[name](name, value)
File "C:\Program Files\Python36\lib\email\headerregistry.py", line 197, in __new__
cls.parse(value, kwds)
File "C:\Program Files\Python36\lib\email\headerregistry.py", line 340, in parse
kwds['parse_tree'] = address_list = cls.value_parser(value)
File "C:\Program Files\Python36\lib\email\headerregistry.py", line 331, in value_parser
address_list, value = parser.get_address_list(value)
File "C:\Program Files\Python36\lib\email\_header_value_parser.py", line 1931, in get_address_list
token, value = get_address(value)
File "C:\Program Files\Python36\lib\email\_header_value_parser.py", line 1908, in get_address
token, value = get_group(value)
File "C:\Program Files\Python36\lib\email\_header_value_parser.py", line 1879, in get_group
if value[0] != ';':
IndexError: string index out of range #----------------------------------------------------- $ test-bug.py
Chris Jones <c@a.test>
joe@where.test
John <jdoe@one.test> |
Please send a pull request(PR) through CPython GitHub(https://github.com/python/cpython) It will be a great experience :) |
@r.david.murray Please take a look PR 7484 :) |
@r.david.murray |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: