Invalid regular expressions in 'Watched Words' makes no watched word work

AI-generated summary

Invalid regular expressions in ‘Watched Words’ causes issues

When the watched words regular expressions setting is enabled, invalid regular expressions break the specific watched word category entirely. blattersturm reported that adding an invalid pattern can cause posts to skip the approval queue and be ignored by the ‘Test’ form. Furthermore, enabling regular expressions with invalid patterns in tags can result in an ‘Error 500’.

Proposed solutions include requiring zero watched words prior to changing the setting sam or adding protection to prevent breaking the site codinghorror. blattersturm also suggested allowing valid regex patterns to be entered when regular expressions are disabled, if wrapped in a / block.

When enabling the watched words regular expressions setting, invalid regular expressions break the specific watched word category entirely.

Reproduction steps

  1. Enable ‘watched words regular expressions’
  2. Add a watched word pattern to ‘Require Approval’, e.g. same issue.
  3. Add an invalid watched word pattern, e.g. *ban* (as would be the case when having wildcards in watched words before enabling regular expressions).
  4. Note that a post containing ‘same issue’ will skip the approval queue, and will be ignored by the ‘Test’ form too.
  5. Remove the invalid watched word.
  6. Note that ‘same issue’ will now correctly match.

Reproduction steps (worse):

  1. Enable ‘watched words regular expressions’ and tags
  2. Add an invalid watched word pattern to ‘Tag’, e.g. *tebex.io* → paid.
  3. Try posting a new topic. This will return ‘Error 500’ with the following result in /logs:
RegexpError (target of repeat operator is not specified: /*tebex.io*/)
app/services/word_watcher.rb:116:in `initialize'
app/services/word_watcher.rb:116:in `new'
app/services/word_watcher.rb:116:in `matches?'
lib/topic_creator.rb:184:in `block in setup_tags'
lib/topic_creator.rb:183:in `each'
lib/topic_creator.rb:183:in `setup_tags'
lib/topic_creator.rb:46:in `create'
lib/post_creator.rb:501:in `create_topic'

Footnote

I think it’d be nice if having regular expressions disabled could still allow a valid regex to be entered similar to wildcards if, say, wrapped in a / block, especially since the toggle will break in a bad way if any old watched words already have wildcards.

3 Likes

Hmm, is there any protection we can add here @sam?

There is a reason this is a behind a site setting @blattersturm – you have to know what you’re doing… regular expressions are quite dangerous.

1 Like

Maybe we require zero watched words prior to changing the setting @nbianca ?

If you try to change it and have watched words we ask you to delete them all?

3 Likes