FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-87720 Fix additional header refolding-quoting edge case (GH-134271) by miss-islington · Pull Request #159067 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 12 additions & 1 deletion Lib/email/_header_value_parser.py
This file contains hidden or 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
Expand Up @@ -169,6 +169,14 @@ def comments(self):
comments.extend(token.comments)
return comments

def contains_token_type(self, *token_types):
if self.token_type in token_types:
return True
for t in self:
if t.contains_token_type(*token_types):
return True
return False

def fold(self, *, policy):
return _refold_parse_tree(self, policy=policy)

Expand Down Expand Up @@ -935,6 +943,9 @@ def pop_trailing_ws(self):
def comments(self):
return []

def contains_token_type(self, *token_types):
return self.token_type in token_types

def __getnewargs__(self):
return(str(self), self.token_type)

Expand Down Expand Up @@ -2863,7 +2874,7 @@ def _refold_parse_tree(parse_tree, *, policy):
continue
tstr = str(part)
if not want_encoding:
if part.token_type in ('ptext', 'vtext'):
if part.token_type == 'ptext' or part.contains_token_type('vtext'):
# Encode if tstr contains special characters.
want_encoding = not SPECIALSNL.isdisjoint(tstr)
else:
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
This file contains hidden or 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
Expand Up @@ -3347,6 +3347,11 @@ def test_address_list_with_specials_in_encoded_word(self):
'A =?utf-8?q?v=C3=A9ry?= long name\n'
' containing =?utf-8?q?a=2C?= comma\n'
' <to@example.com>\n'),
('=?utf-8?Q?a=2C=20123456789012345678901234567890123456?='
' <abc@example.com>',
'=?utf-8?q?a=2C?=\n'
' 123456789012345678901234567890123456\n'
' <abc@example.com>\n'),
]
for (to, folded) in cases:
with self.subTest(to=to):
Expand Down
This file contains hidden or 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,3 @@
Fixed error in :mod:`email` new policies where header folding failed to
detect the need to re-quote text obtained from encoded words in certain
cases.
Loading

Back | FazBrowse Home | New Git URL