Skip to content

Commit 66c306a

Browse files
committed
tools.compile_rule: better whitespace handling for $nick placeholder
If the placeholder is followed by a space, replace it with a pattern that will consume extra whitespace but doesn't require any. If the placeholder is NOT followed by a space, use the original pattern that requires at least one space to match.
1 parent ee3fcb2 commit 66c306a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sopel/tools/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ def compile_rule(nick, pattern, alias_nicks):
214214
nick = re.escape(nick)
215215

216216
pattern = pattern.replace('$nickname', nick)
217-
pattern = pattern.replace('$nick', r'{}[,:]\s+'.format(nick))
217+
pattern = pattern.replace('$nick ', r'{}[,:]\s*'.format(nick)) # @rule('$nick hi')
218+
pattern = pattern.replace('$nick', r'{}[,:]\s+'.format(nick)) # @rule('$nickhi')
218219
flags = re.IGNORECASE
219-
if '\n' in pattern:
220+
if '\n' in pattern: # TODO: Why do we have this? IRC lines can't contain \n
220221
flags |= re.VERBOSE
221222
return re.compile(pattern, flags)
222223

0 commit comments

Comments
 (0)