filtering out "bad" regular expressions from user input
Alex
the_brain at mit.edu
Fri Sep 29 11:21:21 EDT 2000
> We allow users to input regular expressions to our search engine.
> Problem is, when (and they inevitably do, so it's not "if") they input
> a bad regular expression, it sends the backend search engine into a
> tizzy (backend is MySQL, frontend is Python). For example, "^" will
> cause it to match everything, as will "^.*$", "" and ".*".
Can you test the regexp against a few randomly generated strings? If it
matches against any of them, it's going to be pretty promiscuous.
I guess you could also perform the tests in a thread, and kill the
thread if it takes too long. That would go some way to locating really
demanding regexps.
Alex.
--
Speak softly but carry a big carrot.
More information about the Python-list
mailing list