Bekeken woord reguliere expressie crash (2025)

Similar to this one

Repro

  • watched words regular expressions enabled
  • watched words tag action
  • regular expression *abc

Result

It is impossible to create topics or posts

RegexpError (target of repeat operator is not specified: /(*abc)/i)
app/services/word_watcher.rb:239:in `initialize'
app/services/word_watcher.rb:239:in `new'
app/services/word_watcher.rb:239:in `word_matches?'
lib/topic_creator.rb:214:in `block in setup_tags'
lib/topic_creator.rb:213:in `each'
lib/topic_creator.rb:213:in `setup_tags'
lib/topic_creator.rb:48:in `create'
lib/post_creator.rb:493:in `create_topic'

Cause

  • * means “repeat the previous token zero or more times”
  • there is no previous token
2 likes

Dus de regex moet echt gevalideerd worden voordat deze wordt toegestaan? En er moet een redding zijn zodat een ongeldige regex de hele wereld niet kan laten crashen?

1 like

What obviously happened here is that the watched words were regular watched words and * was the wildcard, and then watched words regular expressions enabled was enabled.

So this

1 like

Well, now it’s obvious when you say it like that. :rofl:

Het valideren van regex bij het opslaan lijkt erg logisch.\n\nIk plaats hier een pr-welcome op, maar het team zal dit beoordelen en beslissen of het zinvol is om dit de komende weken te doen om ons toekomstige ondersteuning te besparen.

1 like

That won’t prevent people entering “normal” wildcard expressions, and then turning on watched words regular expressions enabled, which is what happened here.

I think it just needs an exception handler around the regexp call

  def word_matches?(word, case_sensitive: false)
    options = case_sensitive ? nil : Regexp::IGNORECASE
    Regexp.new(WordWatcher.word_to_regexp(word), options).match?(@raw)
  end
2 likes

Thanks for the report @RGJ, this will be fixed by

3 likes

Dit onderwerp werd automatisch gesloten na 10 uur. Nieuwe antwoorden zijn niet meer toegestaan.