צפיתי בקריסת ביטוי רגולרי של מילה (2025)

סיכום מבוסס בינה מלאכותית

A bug report was submitted regarding a crash caused by an invalid regular expression in the watched words feature. The issue occurs when enabling regular expressions for watched words that were initially set as wildcard expressions. Specifically, the regex *abc caused a crash because the * operator had no preceding token. RGJ provided a repro case and error details. pfaffman suggested validating regex before saving and adding exception handling. RGJ clarified the cause of the issue. sam proposed validating regex on save and marked it as pr-welcome. RGJ emphasized the need for exception handling around the regexp call. zogstrip confirmed that the issue will be fixed by a pull request.

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 לייקים

אז באמת הביטוי הרגולרי צריך להיות מאומת לפני שמאפשרים להוסיף אותו? וצריכה להיות הצלה כדי שביטוי רגולרי לא תקין לא יוכל להרוס את כל העולם?

לייק 1

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

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

אימות ביטוי רגולרי בעת שמירה נשמע כמו דבר הגיוני מאוד לעשות.

מוסיף pr-welcome לכך, אך הצוות יבחן ויחליט אם הגיוני לעשות זאת בשבועות הקרובים כדי לחסוך לנו תמיכה עתידית.

לייק 1

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 לייקים

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

https://github.com/discourse/discourse/pull/35217

3 לייקים

נושא זה נסגר אוטומטית לאחר 10 שעות. לא ניתן להוסיף תגובות חדשות.