From 6adeafd1d269ad25f854e50eeb6a420f76c25fa0 Mon Sep 17 00:00:00 2001 From: Michael Bai Date: Tue, 8 Feb 2022 14:19:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=BF=87=E6=BB=A4=E8=A7=84=E5=88=99=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/cmd_filter.py | 7 ++++--- apps/assets/serializers/cmd_filter.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/assets/models/cmd_filter.py b/apps/assets/models/cmd_filter.py index 535f56ed8..d7eac13eb 100644 --- a/apps/assets/models/cmd_filter.py +++ b/apps/assets/models/cmd_filter.py @@ -133,9 +133,10 @@ class CommandFilterRule(OrgModelMixin): s = r'{}'.format('|'.join(regex)) return s - def compile_regex(self, regex): + @staticmethod + def compile_regex(regex, ignore_case): try: - if self.ignore_case: + if ignore_case: pattern = re.compile(regex, re.IGNORECASE) else: pattern = re.compile(regex) @@ -146,7 +147,7 @@ class CommandFilterRule(OrgModelMixin): return True, '', pattern def match(self, data): - succeed, error, pattern = self.compile_regex(regex=self.pattern) + succeed, error, pattern = self.compile_regex(self.pattern, self.ignore_case) if not succeed: return self.ACTION_UNKNOWN, '' diff --git a/apps/assets/serializers/cmd_filter.py b/apps/assets/serializers/cmd_filter.py index df60dc21a..1d798d7eb 100644 --- a/apps/assets/serializers/cmd_filter.py +++ b/apps/assets/serializers/cmd_filter.py @@ -66,7 +66,8 @@ class CommandFilterRuleSerializer(BulkOrgResourceModelSerializer): regex = CommandFilterRule.construct_command_regex(content) else: regex = content - succeed, error, pattern = CommandFilterRule.compile_regex(regex) + ignore_case = self.initial_data.get('ignore_case') + succeed, error, pattern = CommandFilterRule.compile_regex(regex, ignore_case) if not succeed: raise serializers.ValidationError(error) return content