-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
bpo-29412: Fix indexError when parsing a header value ending unexpectedly #14387
Conversation
…er_value_parser.py and created tests in test__header_value_parser.py for CFWS.
To mention this borrows a test case from GH-6907 (which seeems to be abandoned, which is why I am proposing this new PR to override that). The fix however is different than GH-6907, which is why I haven't added a |
Also, modify the testcase.
2941cb3
to
e28cbc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for providing the test. It is always useful. :)
@@ -1360,6 +1360,9 @@ def get_word(value): | |||
leader, value = get_cfws(value) | |||
else: | |||
leader = None | |||
if not value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to catch all false-y values or just None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to catch None
and empty string ''
values, both of which could cause IndexError when running value[0]
. It could also be caused by empty list, empty tuple etc etc, but I don't think value
can be of those datatypes.
Remove implicit concatenation of strings and move the string to next line so that it can fit properly under 79 chars.
I'm assuming this needs backporting to 3.7 and 3.8. |
…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. (cherry picked from commit 7213df7) Co-authored-by: Abhilash Raj <[email protected]>
GH-14411 is a backport of this pull request to the 3.8 branch. |
GH-14412 is a backport of this pull request to the 3.7 branch. |
…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. (cherry picked from commit 7213df7) Co-authored-by: Abhilash Raj <[email protected]>
…edly (GH-14387) (GH-14412) * 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. (cherry picked from commit 7213df7) Co-authored-by: Abhilash Raj <[email protected]>
…edly (GH-14387) (GH-14411) * 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. (cherry picked from commit 7213df7) Co-authored-by: Abhilash Raj <[email protected]>
…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.
…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.
When parsing a word, if the value is None, we should raise
HeaderParseError
instead of continuing silently. This helps fix the IndexError.Part of the patch is from GH-6907, so thanks to @TyrannosourceExe.
https://bugs.python.org/issue29412