Check that subscription regexen compile before accepting them
Previously we blindly accepted any string as a regex, but then it could fail to compile at search-time when a track topic got updated, which would cause the bot to crash. So do a precautionary compile of the regex in order to ensure we only accept valid regexen. Change-Id: Id347b88adfc7150ff26550cf9170071e7ac33227
This commit is contained in:
parent
4fbaf41725
commit
b14ec32f05
@ -222,6 +222,11 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot):
|
|||||||
self.send_priv_or_pub(
|
self.send_priv_or_pub(
|
||||||
reply_to, nick,
|
reply_to, nick,
|
||||||
"Your current subscription regex is: " + existing_re)
|
"Your current subscription regex is: " + existing_re)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
re.compile(new_re)
|
||||||
|
except Exception as e:
|
||||||
|
self.send_priv_or_pub(reply_to, nick, "Invalid regex: %s" % e)
|
||||||
else:
|
else:
|
||||||
self.data.set_subscription(nick, new_re)
|
self.data.set_subscription(nick, new_re)
|
||||||
self.send_priv_or_pub(
|
self.send_priv_or_pub(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user