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
|
@ -223,12 +223,17 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot):
|
||||||
reply_to, nick,
|
reply_to, nick,
|
||||||
"Your current subscription regex is: " + existing_re)
|
"Your current subscription regex is: " + existing_re)
|
||||||
else:
|
else:
|
||||||
self.data.set_subscription(nick, new_re)
|
try:
|
||||||
self.send_priv_or_pub(
|
re.compile(new_re)
|
||||||
reply_to, nick,
|
except Exception as e:
|
||||||
"Subscription set to " + new_re +
|
self.send_priv_or_pub(reply_to, nick, "Invalid regex: %s" % e)
|
||||||
(" (was %s)" % existing_re if existing_re else "")
|
else:
|
||||||
)
|
self.data.set_subscription(nick, new_re)
|
||||||
|
self.send_priv_or_pub(
|
||||||
|
reply_to, nick,
|
||||||
|
"Subscription set to " + new_re +
|
||||||
|
(" (was %s)" % existing_re if existing_re else "")
|
||||||
|
)
|
||||||
|
|
||||||
def unsubscribe(self, reply_to, nick):
|
def unsubscribe(self, reply_to, nick):
|
||||||
existing_re = self.data.get_subscription(nick)
|
existing_re = self.data.get_subscription(nick)
|
||||||
|
|
Loading…
Reference in New Issue