Skip to content
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] Try compiling RegEx before adding #665

Open
wants to merge 2 commits into
base: V3/testing
Choose a base branch
from

Conversation

quachtridat
Copy link
Member

Summary

This PR resolves #646 by compiling RegEx before adding a RegEx string into WordFilter's books.

Details

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 #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.
@quachtridat quachtridat requested a review from a team October 20, 2024 02:10
Merge branch `V3/testing` into
`quachtridat/issue646-wordfilter-cog-validate-regex`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WordFilter] Better validate and handle regex
1 participant