Fix relaxed body canoncalization & introduce further unit tests for both simple and relaxed mode

This commit is contained in:
Matthew Palmer
2017-10-25 13:06:00 +01:00
parent 939c3f8bba
commit 6de4fa79cd
2 changed files with 49 additions and 2 deletions
+9 -2
View File
@@ -48,6 +48,13 @@ def unfold_header_value(content):
return re.sub(b"\r\n", b"", content)
def correct_empty_body(content):
if content == b"\r\n":
return ""
else:
return content
class Simple:
"""Class that represents the "simple" canonicalization algorithm."""
@@ -85,8 +92,8 @@ class Relaxed:
# Remove all trailing WSP at end of lines.
# Compress non-line-ending WSP to single space.
# Ignore all empty lines at the end of the message body.
return strip_trailing_lines(
compress_whitespace(strip_trailing_whitespace(body)))
return correct_empty_body(strip_trailing_lines(
compress_whitespace(strip_trailing_whitespace(body))))
class CanonicalizationPolicy: