progval / Limnoria

A robust, full-featured, and user/programmer-friendly Python IRC bot, with many existing plugins.
https://docs.limnoria.net/
Other
621 stars 174 forks source link

MessageParser chokes on matches with \ #1497

Closed apfelkuchen6 closed 2 years ago

apfelkuchen6 commented 2 years ago

Consider the following:

<human> @messageparser add test(.*)test "echo $1"
<bot> human: The operation succeeded.
<human> testhello\xhellotest

Expected behavior:

<bot> hello\xhello

Observed behavior:

Nov 25 23:19:16 nixos supybot[10377]: ERROR 2021-11-25T23:19:16 Uncaught exception in MessageParser.__call__:
Nov 25 23:19:16 nixos supybot[10377]: Traceback (most recent call last):
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/8dxxjbiyxwkvh53q5kh6nydla2anacgi-python3-3.9.6/lib/python3.9/sre_parse.py", line 1039, in parse_template
Nov 25 23:19:16 nixos supybot[10377]:     this = chr(ESCAPES[this][1])
Nov 25 23:19:16 nixos supybot[10377]: KeyError: '\\x'
Nov 25 23:19:16 nixos supybot[10377]: During handling of the above exception, another exception occurred:
Nov 25 23:19:16 nixos supybot[10377]: Traceback (most recent call last):
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/s6009jpy1q6as3zc6cw872shkzgn3fdy-python3-3.9.6-env/lib/python3.9/site-packages/supybot/log.py", line 370, in m
Nov 25 23:19:16 nixos supybot[10377]:     return f(self, *args, **kwargs)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/s6009jpy1q6as3zc6cw872shkzgn3fdy-python3-3.9.6-env/lib/python3.9/site-packages/supybot/irclib.py", line 203, in __call__
Nov 25 23:19:16 nixos supybot[10377]:     method(irc, msg)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/s6009jpy1q6as3zc6cw872shkzgn3fdy-python3-3.9.6-env/lib/python3.9/site-packages/supybot/plugins/MessageParser/plugin.py", line 199, in doPrivmsg
Nov 25 23:19:16 nixos supybot[10377]:     self.do_privmsg_notice(irc, msg)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/s6009jpy1q6as3zc6cw872shkzgn3fdy-python3-3.9.6-env/lib/python3.9/site-packages/supybot/plugins/MessageParser/plugin.py", line 186, in do_privmsg_notice
Nov 25 23:19:16 nixos supybot[10377]:     thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/8dxxjbiyxwkvh53q5kh6nydla2anacgi-python3-3.9.6/lib/python3.9/re.py", line 210, in sub
Nov 25 23:19:16 nixos supybot[10377]:     return _compile(pattern, flags).sub(repl, string, count)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/8dxxjbiyxwkvh53q5kh6nydla2anacgi-python3-3.9.6/lib/python3.9/re.py", line 327, in _subx
Nov 25 23:19:16 nixos supybot[10377]:     template = _compile_repl(template, pattern)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/8dxxjbiyxwkvh53q5kh6nydla2anacgi-python3-3.9.6/lib/python3.9/re.py", line 318, in _compile_repl
Nov 25 23:19:16 nixos supybot[10377]:     return sre_parse.parse_template(repl, pattern)
Nov 25 23:19:16 nixos supybot[10377]:   File "/nix/store/8dxxjbiyxwkvh53q5kh6nydla2anacgi-python3-3.9.6/lib/python3.9/sre_parse.py", line 1042, in parse_template
Nov 25 23:19:16 nixos supybot[10377]:     raise s.error('bad escape %s' % this, len(this))
Nov 25 23:19:16 nixos supybot[10377]: re.error: bad escape \x at position 5
Nov 25 23:19:16 nixos supybot[10377]: ERROR 2021-11-25T23:19:16 Exception id: 0xe78bf
progval commented 2 years ago

Wow, this is incredibly silly/surprising behavior from Python's re.sub.

Thanks for the detailed report, this is now fixed in the testing branch.