regex-search icon indicating copy to clipboard operation
regex-search copied to clipboard

Expressions with the * operator runs infinitely

Open jack0lantern opened this issue 9 years ago • 4 comments

On this page: http://docs.oracle.com/javase/tutorial/essential/concurrency/procthread.html

I searched s* and it appears to enter an infinite loop in v 1.8. Eventually, the page crashes.

jack0lantern avatar Jul 31 '15 03:07 jack0lantern

Whoa... well this is bad. I'm not sure what the proper fix is for this or when I'll get time to look into it, but thanks for the report.

gsingh93 avatar Jul 31 '15 03:07 gsingh93

I can confirm this.

Please use s+ (at least one s) instead. It is more efficient than s* (0 or more s) because the latter even matches empty strings all over the page.

ComFreek avatar Jul 31 '15 08:07 ComFreek

Maybe we should disallow searching any two character regex where the second character is a '', or the one character regex where '' is the only character. Does that cover all of the bad cases or are there other cases we're missing?

gsingh93 avatar Jul 31 '15 17:07 gsingh93

Some test cases performed on the website mentioned in the first comment:

1 works:         .*
2 works:         ..........
3 works:         .*.*.*.*.*.*.*
4 works:         (.+)*
5 fails:            s*

It seems that some optimization is done in case 1 as opposed to case 5.

So indeed, it might be a good idea to disallow a regex consisting of any character followed by * only. Or shall we rather add general hint/warning that usage of '+' is encouraged contrary to '*'

PS: You can escape asterisks and other Markdown syntax by a backslash: \ *

ComFreek avatar Jul 31 '15 17:07 ComFreek