fix: 修改命令过滤规则生成正则表达式的逻辑,提高命令过滤准确性

pull/6947/head
Michael Bai 2021-12-08 10:16:42 +08:00 committed by Jiangjie.Bai
parent d56de16563
commit d72aa34513
1 changed files with 9 additions and 1 deletions

View File

@ -75,9 +75,17 @@ class CommandFilterRule(OrgModelMixin):
if self.type == 'command': if self.type == 'command':
regex = [] regex = []
content = self.content.replace('\r\n', '\n') content = self.content.replace('\r\n', '\n')
for cmd in content.split('\n'): for _cmd in content.split('\n'):
cmd = re.sub(r'\s+', ' ', _cmd)
cmd = re.escape(cmd) cmd = re.escape(cmd)
cmd = cmd.replace('\\ ', '\s+') cmd = cmd.replace('\\ ', '\s+')
# 有空格就不能 铆钉单词了
if ' ' in _cmd:
regex.append(cmd)
continue
# 如果是单个字符
if cmd[-1].isalpha(): if cmd[-1].isalpha():
regex.append(r'\b{0}\b'.format(cmd)) regex.append(r'\b{0}\b'.format(cmd))
else: else: