[ruby-core:118867] [Ruby master Bug#20681] Regular expression warnings are treated as compiler warnings during runtime

Issue #20681 has been reported by Earlopain (A S). ---------------------------------------- Bug #20681: Regular expression warnings are treated as compiler warnings during runtime https://bugs.ruby-lang.org/issues/20681 * Author: Earlopain (A S) * Status: Open * ruby -v: 3.3.4 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I have some code that recieves arbitrary input and parses it as a regexp. To supress potential warnings I'm defining the `warn` method. Unfortunately it is not getting called: ```rb def warn(...) puts "CALLED" end source = "/\w**/" Regexp.new(source) ``` Running this emits a warning and doesn't print "CALLED": ``` $ ruby test.rb test.rb:6: warning: regular expression has redundant nested repeat operator '*': /\/w**\// ``` I looked a bit at the code and found something which I think is supposed to handle this case but it seems like its not checking against the right thing: https://github.com/ruby/ruby/blob/4dbf386ca248df0f47f31dc28cdeabe8d4477e5b/r... -- https://bugs.ruby-lang.org/

Issue #20681 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Feedback You may want to re-define `Warning.warn`. ---------------------------------------- Bug #20681: Regular expression warnings are treated as compiler warnings during runtime https://bugs.ruby-lang.org/issues/20681#change-109445 * Author: Earlopain (A S) * Status: Feedback * ruby -v: 3.3.4 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I have some code that recieves arbitrary input and parses it as a regexp. To supress potential warnings I'm defining the `warn` method. Unfortunately it is not getting called: ```rb def warn(...) puts "CALLED" end source = "/\w**/" Regexp.new(source) ``` Running this emits a warning and doesn't print "CALLED": ``` $ ruby test.rb test.rb:6: warning: regular expression has redundant nested repeat operator '*': /\/w**\// ``` I looked a bit at the code and found something which I think is supposed to handle this case but it seems like its not checking against the right thing: https://github.com/ruby/ruby/blob/4dbf386ca248df0f47f31dc28cdeabe8d4477e5b/r... -- https://bugs.ruby-lang.org/

Issue #20681 has been updated by Earlopain (A S). nobu (Nobuyoshi Nakada) wrote in #note-1:
You may want to re-define `Warning.warn`.
Thank you, that works. Apologies for the wrong report. ---------------------------------------- Bug #20681: Regular expression warnings are treated as compiler warnings during runtime https://bugs.ruby-lang.org/issues/20681#change-109447 * Author: Earlopain (A S) * Status: Feedback * ruby -v: 3.3.4 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I have some code that recieves arbitrary input and parses it as a regexp. To supress potential warnings I'm defining the `warn` method. Unfortunately it is not getting called: ```rb def warn(...) puts "CALLED" end source = "/\w**/" Regexp.new(source) ``` Running this emits a warning and doesn't print "CALLED": ``` $ ruby test.rb test.rb:6: warning: regular expression has redundant nested repeat operator '*': /\/w**\// ``` I looked a bit at the code and found something which I think is supposed to handle this case but it seems like its not checking against the right thing: https://github.com/ruby/ruby/blob/4dbf386ca248df0f47f31dc28cdeabe8d4477e5b/r... -- https://bugs.ruby-lang.org/
participants (2)
-
Earlopain (A S)
-
nobu (Nobuyoshi Nakada)