-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WordFilter] Better validate and handle regex #646
Comments
Regarding the particular RegEx pattern concerned, is it a pattern that we inserted into the cog? If the problem doesn't take place programmatically, then I'd see it as a human error and we need to fix the problematic patterns. |
This pattern was restored from a backup, so it was entered in by someone, but we should validate the pattern before adding it in. |
Might be better to handle this without raising an exception; could log it in the console instead so as to keep it working |
Would constructing a
Right. Some error log lines should definitely help. |
This commit resolves SFUAnime#646 by compiling RegEx before adding a RegEx string into WordFilter's books. With this commit, at word filter insertion time (`[p]wordfilter regex add <word>`), `re.compile` will be invoked, and if there is a `re.error`, a message will be sent to where the command has been invoked to notify the user executing the command about the invalid RegEx pattern that was input. Without this commit, the cog will crash when it tries to substitute/match/search invalid RegEx patterns during handling of an `on_message` event. See SFUAnime#646 for an example traceback.
This commit resolves SFUAnime#646 by compiling RegEx before adding a RegEx string into WordFilter's books. With this commit, at word filter insertion time (`[p]wordfilter regex add <word>`), `re.compile` will be invoked, and if there is a `re.error`, a message will be sent to where the command has been invoked to notify the user executing the command about the invalid RegEx pattern that was input. Without this commit, the cog will crash when it tries to substitute/match/search invalid RegEx patterns during handling of an `on_message` event. See SFUAnime#646 for an example traceback.
In other cogs that hook into WordFilter, we hit a
multiple repeat
error on the following regex string:bl[o0]*{0,3}w j[o0]*{0,3}bs
. Of particular interest is the*
operator, which was what it was complaining about, because{0,3}
is trying to operate on*
which doesn't make sense.We should find a way to better handle this on insertion and within the
_filterWord
function.Logs below:
The text was updated successfully, but these errors were encountered: