Fix empty body canonicalization for relaxed canonicalization (LP: #1727319)
This commit is contained in:
@@ -8,6 +8,8 @@ UNRELEASED Version 0.7.0
|
|||||||
exclude usage with sha1. Can be overriden.
|
exclude usage with sha1. Can be overriden.
|
||||||
- Update ARC processing to current draft.
|
- Update ARC processing to current draft.
|
||||||
- Fix arcverify tag requirements (LP: #1710312)
|
- Fix arcverify tag requirements (LP: #1710312)
|
||||||
|
- Fix empty body canonicalization for relaxed canonicalization (LP: #1727319)
|
||||||
|
* Thanks to Matthew Palmer for the report and the proposed fix
|
||||||
|
|
||||||
2017-05-30 Version 0.6.2
|
2017-05-30 Version 0.6.2
|
||||||
- Fixed problem with header folding that caused the first line to be
|
- Fixed problem with header folding that caused the first line to be
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ def unfold_header_value(content):
|
|||||||
return re.sub(b"\r\n", b"", content)
|
return re.sub(b"\r\n", b"", content)
|
||||||
|
|
||||||
|
|
||||||
|
def correct_empty_body(content):
|
||||||
|
if content == b"\r\n":
|
||||||
|
return b""
|
||||||
|
else:
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
class Simple:
|
class Simple:
|
||||||
"""Class that represents the "simple" canonicalization algorithm."""
|
"""Class that represents the "simple" canonicalization algorithm."""
|
||||||
|
|
||||||
@@ -85,8 +92,8 @@ class Relaxed:
|
|||||||
# Remove all trailing WSP at end of lines.
|
# Remove all trailing WSP at end of lines.
|
||||||
# Compress non-line-ending WSP to single space.
|
# Compress non-line-ending WSP to single space.
|
||||||
# Ignore all empty lines at the end of the message body.
|
# Ignore all empty lines at the end of the message body.
|
||||||
return strip_trailing_lines(
|
return correct_empty_body(strip_trailing_lines(
|
||||||
compress_whitespace(strip_trailing_whitespace(body)))
|
compress_whitespace(strip_trailing_whitespace(body))))
|
||||||
|
|
||||||
|
|
||||||
class CanonicalizationPolicy:
|
class CanonicalizationPolicy:
|
||||||
|
|||||||
@@ -53,6 +53,26 @@ class TestSimpleAlgorithmBody(BaseCanonicalizationTest):
|
|||||||
b'Foo \tbar \r\n',
|
b'Foo \tbar \r\n',
|
||||||
b'Foo \tbar \r\n\r\n')
|
b'Foo \tbar \r\n\r\n')
|
||||||
|
|
||||||
|
def test_adds_crlf(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'Foo bar\r\n',
|
||||||
|
b'Foo bar')
|
||||||
|
|
||||||
|
def test_empty_body(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'\r\n',
|
||||||
|
b'')
|
||||||
|
|
||||||
|
def test_single_crlf_body(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'\r\n',
|
||||||
|
b'\r\n')
|
||||||
|
|
||||||
|
def test_multiple_crlf_body(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'\r\n',
|
||||||
|
b'\r\n\r\n')
|
||||||
|
|
||||||
|
|
||||||
class TestRelaxedAlgorithmHeaders(BaseCanonicalizationTest):
|
class TestRelaxedAlgorithmHeaders(BaseCanonicalizationTest):
|
||||||
|
|
||||||
@@ -98,6 +118,26 @@ class TestRelaxedAlgorithmBody(BaseCanonicalizationTest):
|
|||||||
b'Foo\r\nbar\r\n',
|
b'Foo\r\nbar\r\n',
|
||||||
b'Foo\r\nbar\r\n\r\n\r\n')
|
b'Foo\r\nbar\r\n\r\n\r\n')
|
||||||
|
|
||||||
|
def test_adds_crlf(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'Foo bar\r\n',
|
||||||
|
b'Foo bar')
|
||||||
|
|
||||||
|
def test_empty_body(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'',
|
||||||
|
b'')
|
||||||
|
|
||||||
|
def test_single_crlf_body(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'',
|
||||||
|
b'\r\n')
|
||||||
|
|
||||||
|
def test_multiple_crlf_body(self):
|
||||||
|
self.assertCanonicalForm(
|
||||||
|
b'',
|
||||||
|
b'\r\n\r\n')
|
||||||
|
|
||||||
|
|
||||||
class TestCanonicalizationPolicyFromCValue(unittest.TestCase):
|
class TestCanonicalizationPolicyFromCValue(unittest.TestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user