8000 bpo-39040: Fix parsing of email mime headers with whitespace between encoded-words. by maxking · Pull Request #17620 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39040: Fix parsing of email mime headers with whitespace between encoded-words. #17620

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

Merged
merged 4 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove empty lines, add a new test and update the news entry.
  • Loading branch information
maxking committed Dec 17, 2019
commit bf2cb76009d72869d9df6550b473b5818ceab311
2 changes: 0 additions & 2 deletions Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,13 +1226,11 @@ def get_bare_quoted_string(value):
valid_ew = True
except errors.HeaderParseError:
token, value = get_qcontent(value)

# Collapse the whitespace between two encoded words that occur in a
# bare-quoted-string.
if valid_ew and len(bare_quoted_string) > 1:
if (bare_quoted_string[-1].token_type == 'fws' and
bare_quoted_string[-2].token_type == 'encoded-word'):

bare_quoted_string[-1] = EWWhiteSpaceTerminal(
bare_quoted_string[-1], 'fws')
else:
Expand Down
12 changes: 11 additions & 1 deletion Lib/test/test_email/test_headerregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def content_disp_as_value(self,
{'filename': 'foo'},
[errors.InvalidHeaderDefect]),

'invalid_value_with_fws_bw_ew': (
'invalid_parameter_value_with_fws_between_ew': (
'attachment; filename="=?UTF-8?Q?Schulbesuchsbest=C3=A4ttigung=2E?='
' =?UTF-8?Q?pdf?="',
'attachment',
Expand All @@ -882,6 +882,16 @@ def content_disp_as_value(self,
('attachment; filename="Schulbesuchsbestättigung.pdf"'),
('Content-Disposition: attachment;\n'
' filename*=utf-8\'\'Schulbesuchsbest%C3%A4ttigung.pdf\n'),
),

'parameter_value_with_fws_between_tokens': (
'attachment; filename="File Name With Spaces.pdf"',
'attachment',
{'filename': 'File Name With Spaces.pdf'},
[],
'attachment; filename="File Name With Spaces.pdf"',
('Content-Disposition: attachment; '
'filename="File Name With Spaces.pdf"\n'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. We need a test with something like "File =?utf-8?q?Name?= With Spaces.pdf". That should have spaces around Name...we want to make sure we aren't removing spaces around encoded words that aren't next to other encoded words.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be looking at the outdated diff, from a previous commit.

There should be 4 commits in the PR, and your requested changes are in the last 2 commits.

)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Fix parsing of invalid Content-Disposition email headers by collapsing
whitespace between encoded words in a bare-quote-string.
Fix parsing of invalid mime headers parameters by collapsing whitespace between
encoded words in a bare-quote-string.
0