5a677c1ee31e1d6cb9b91cda2f1b89abf40efbe2
[openwrt-packages.git] /
1 From 4337e366163278815ea9fc6c952bffb579e885a0 Mon Sep 17 00:00:00 2001
2 From: sebres <info@sebres.de>
3 Date: Tue, 21 Jun 2022 16:56:57 +0200
4 Subject: [PATCH] wrap global flags like ((?i)xxx) or (?:(?i)xxx) to local
5  flags (?i:xxx) if supported by RE-engine in the python version
6
7 ---
8  fail2ban/server/failregex.py | 10 ++++++++++
9  1 file changed, 10 insertions(+)
10
11 --- a/fail2ban/server/failregex.py
12 +++ b/fail2ban/server/failregex.py
13 @@ -91,6 +91,13 @@ R_MAP = {
14         "port": "fport",
15  }
16  
17 +# map global flags like ((?i)xxx) or (?:(?i)xxx) to local flags (?i:xxx) if supported by RE-engine in this python version:
18 +try:
19 +       re.search("^re(?i:val)$", "reVAL")
20 +       R_GLOB2LOCFLAGS = ( re.compile(r"(?<!\\)\((?:\?:)?(\(\?[a-z]+)\)"), r"\1:" )
21 +except:
22 +       R_GLOB2LOCFLAGS = ()
23 +
24  def mapTag2Opt(tag):
25         tag = tag.lower()
26         return R_MAP.get(tag, tag)
27 @@ -128,6 +135,9 @@ class Regex:
28                 #
29                 if regex.lstrip() == '':
30                         raise RegexException("Cannot add empty regex")
31 +               # special handling wrapping global flags to local flags:
32 +               if R_GLOB2LOCFLAGS:
33 +                       regex = R_GLOB2LOCFLAGS[0].sub(R_GLOB2LOCFLAGS[1], regex)
34                 try:
35                         self._regexObj = re.compile(regex, re.MULTILINE if multiline else 0)
36                         self._regex = regex
git clone https://git.99rst.org/PROJECT