From 3c2beaf70ecd39b28e1d6ea64870ed2343bfb4ba Mon Sep 17 00:00:00 2001 From: Scott Kitterman Date: Mon, 29 Oct 2018 19:53:12 -0400 Subject: [PATCH] - Python 3.7 compatibility fixup for dkim.canonicalization. strip_trailing_lines due to changed RE.sub() processing (LP: #1800313) --- ChangeLog | 2 ++ dkim/canonicalization.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cfc36e1..6492417 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ UNRELEASED Version 0.9.0 (Thomas Ward) - PEP8 Blank Lines Style Issues (LP: #1782596) (Thomas Ward) + - Python 3.7 compatibility fixup for dkim.canonicalization. + strip_trailing_lines due to changed RE.sub() processing (LP: #1800313) 2018-06-16 Version 0.8.1 - Correctly fold lines at or near the maximum line length (fix folding diff --git a/dkim/canonicalization.py b/dkim/canonicalization.py index c69cd23..bb04b1c 100644 --- a/dkim/canonicalization.py +++ b/dkim/canonicalization.py @@ -41,7 +41,14 @@ def compress_whitespace(content): def strip_trailing_lines(content): - return re.sub(b"(\r\n)*$", b"\r\n", content) + content = re.sub(b"(\r\n)*$", b"\r\n", content) + # Yes, this is horrible, but regex processing changed in python3.7 and it + # is the least horrible solution I came up with for python2.7, python3.7, + # and python3 << 3.7 combined support. Better solution welcome. + if len(content) >= 4: + if (content[len(content)-4:] == b'\r\n\r\n'): + content = content[:len(content)-2] + return content def unfold_header_value(content):