From 31a6c8cf5d8897b957fa47edb8c4dcdd5ef57836 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 13 Jan 2020 20:12:16 +0100 Subject: [PATCH] closes gh-2599: fixes `splitwords` for unicode string --- fail2ban/helpers.py | 2 +- fail2ban/tests/misctestcase.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py index 213a405f..241543c1 100644 --- a/fail2ban/helpers.py +++ b/fail2ban/helpers.py @@ -291,7 +291,7 @@ def splitwords(s): """ if not s: return [] - return filter(bool, map(str.strip, re.split('[ ,\n]+', s))) + return filter(bool, map(lambda v: v.strip(), re.split('[ ,\n]+', s))) if sys.version_info >= (3,5): eval(compile(r'''if 1: diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index cd27ad92..9b986f53 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -66,6 +66,8 @@ class HelpersTest(unittest.TestCase): self.assertEqual(splitwords(' 1, 2 , '), ['1', '2']) self.assertEqual(splitwords(' 1\n 2'), ['1', '2']) self.assertEqual(splitwords(' 1\n 2, 3'), ['1', '2', '3']) + # string as unicode: + self.assertEqual(splitwords(u' 1\n 2, 3'), ['1', '2', '3']) if sys.version_info >= (2,7):