From aa6f4f0385a3deae8925615ccfcc4fb262e819a1 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sun, 4 Nov 2018 14:06:03 +0000 Subject: [PATCH] parser: Ensure whitespace is stripped for long headers RFC2822 states that long headers can be wrapped using CRLF followed by WSP [1]. For example: Subject: Foo bar, baz Should be parsed as: Foo bar,baz While we were stripping the former, we were not stripping the latter. This mean that we ended up with the following: Foo bar, baz Resolve this. Signed-off-by: Stephen Finucane Closes: #197 (cherry picked from commit 841f966b8d54b2f51ab1c498eed6e5391f2546a9) --- patchwork/parser.py | 1 + patchwork/tests/test_parser.py | 2 ++ releasenotes/notes/issue-197-4f7594db1e4c9887.yaml | 7 +++++++ 3 files changed, 10 insertions(+) create mode 100644 releasenotes/notes/issue-197-4f7594db1e4c9887.yaml diff --git a/patchwork/parser.py b/patchwork/parser.py index 40a80f26..0d335b71 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -56,6 +56,7 @@ logger = logging.getLogger(__name__) def normalise_space(value): + value = ''.join(re.split(r'\n\s+', value)) whitespace_re = re.compile(r'\s+') return whitespace_re.sub(' ', value).strip() diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index e99cf214..b9336d37 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -846,6 +846,8 @@ class SubjectTest(TestCase): self.assertEqual(clean_subject('[PATCH] meep'), ('meep', [])) self.assertEqual(clean_subject("[PATCH] meep \n meep"), ('meep meep', [])) + self.assertEqual(clean_subject("[PATCH] meep,\n meep"), + ('meep,meep', [])) self.assertEqual(clean_subject('[PATCH RFC] meep'), ('[RFC] meep', ['RFC'])) self.assertEqual(clean_subject('[PATCH,RFC] meep'), diff --git a/releasenotes/notes/issue-197-4f7594db1e4c9887.yaml b/releasenotes/notes/issue-197-4f7594db1e4c9887.yaml new file mode 100644 index 00000000..2777fbc2 --- /dev/null +++ b/releasenotes/notes/issue-197-4f7594db1e4c9887.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Long headers can be wrapped using CRLF followed by WSP (whitespace). This + whitespace was not being stripped, resulting in errant whitespace being + saved for the patch subject. This is resolved though existing patches and + cover letters will need to be updated manually. -- 2.47.3