Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cafd79d9
Commit
cafd79d9
authored
Mar 23, 2011
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#11590: fix quoprimime decode handling of empty strings and line endings.
parent
ec1b5b88
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
Lib/email/quoprimime.py
Lib/email/quoprimime.py
+3
-3
Lib/email/test/test_email.py
Lib/email/test/test_email.py
+15
-0
No files found.
Lib/email/quoprimime.py
View file @
cafd79d9
...
...
@@ -135,9 +135,9 @@ def header_encode(header_bytes, charset='iso-8859-1'):
charset names the character set to use in the RFC 2046 header. It
defaults to iso-8859-1.
"""
# Return empty headers
unchanged
# Return empty headers
as an empty string.
if
not
header_bytes
:
return
str
(
header_bytes
)
return
''
# Iterate over every byte, encoding if necessary.
encoded
=
[]
for
octet
in
header_bytes
:
...
...
@@ -268,7 +268,7 @@ def decode(encoded, eol=NL):
if
i
==
n
:
decoded
+=
eol
# Special case if original string did not end with eol
if
not
encoded
.
endswith
(
eol
)
and
decoded
.
endswith
(
eol
):
if
encoded
[
-
1
]
not
in
'
\
r
\
n
'
and
decoded
.
endswith
(
eol
):
decoded
=
decoded
[:
-
1
]
return
decoded
...
...
Lib/email/test/test_email.py
View file @
cafd79d9
...
...
@@ -2890,6 +2890,9 @@ class TestQuopri(unittest.TestCase):
encoded_header
=
quoprimime
.
header_encode
(
header
,
charset
)
self
.
assertEqual
(
encoded_header
,
expected_encoded_header
)
def
test_header_encode_null
(
self
):
self
.
_test_header_encode
(
b''
,
''
)
def
test_header_encode_one_word
(
self
):
self
.
_test_header_encode
(
b'hello'
,
'=?iso-8859-1?q?hello?='
)
...
...
@@ -2946,6 +2949,15 @@ class TestQuopri(unittest.TestCase):
def
test_decode_one_line_lf
(
self
):
self
.
_test_decode
(
'hello
\
n
'
,
'hello
\
n
'
)
def
test_decode_one_line_cr
(
self
):
self
.
_test_decode
(
'hello
\
r
'
,
'hello
\
n
'
)
def
test_decode_one_line_nl
(
self
):
self
.
_test_decode
(
'hello
\
n
'
,
'helloX'
,
eol
=
'X'
)
def
test_decode_one_line_crnl
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
'
,
'helloX'
,
eol
=
'X'
)
def
test_decode_one_line_one_word
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
world'
,
'hello
\
n
world'
)
...
...
@@ -2955,6 +2967,9 @@ class TestQuopri(unittest.TestCase):
def
test_decode_two_lines
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
world
\
r
\
n
'
,
'hello
\
n
world
\
n
'
)
def
test_decode_two_lines_eol
(
self
):
self
.
_test_decode
(
'hello
\
r
\
n
world
\
r
\
n
'
,
'helloXworldX'
,
eol
=
'X'
)
def
test_decode_one_long_line
(
self
):
self
.
_test_decode
(
'Spam'
*
250
,
'Spam'
*
250
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment