Issue #15938 has been updated by dlee (David Lee).


Jeremy,

Thank you for the update. We know that Ruby 2.5+ has fixed this issue, but we were hoping the fix could be backported. Do you know if there is any workaround to reliably get Regexp to throw those errors?

Nobuyoshi,

Thanks, we understand that the Regexp is invalid. We were hoping that Ruby would deterministically throw the error, since we're relying on it to validate user-submitted regexp.

----------------------------------------
Bug #15938: Error thrown undeterministically: `RegexpError: empty range in char class`
https://bugs.ruby-lang.org/issues/15938#change-78722

* Author: dlee (David Lee)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.4.6
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
When instantiating a Regexp, we only sometimes see `RegexpError: empty range in char class`.

To reproduce:
`100.times { Regexp.new("^([\\w'+-.%]+@[\\w-.]+\\.[A-Za-z]{2,25})(,[\\w+-.%]+@[\\w-.]+\\.[A-Za-z]{2,4}){0,4}$") }`
usually does not throw the error, but
`100000.times { Regexp.new("^([\\w'+-.%]+@[\\w-.]+\\.[A-Za-z]{2,25})(,[\\w+-.%]+@[\\w-.]+\\.[A-Za-z]{2,4}){0,4}$") }`
usually throws the error.

Furthermore, sometimes accompanying calls matter:
`10.times { Regexp.new("[\\w-.]"); Regexp.new("[\\w-]") }`
usually does not throw the error, but
`10.times { Regexp.new("[\\w-.]") }`
usually throws the error.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>