Project

General

Profile

Actions

Bug #20681

closed

Regular expression warnings are treated as compiler warnings during runtime

Added by Earlopain (Earlopain _) 5 months ago. Updated 5 months ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:118867]

Description

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:

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/regparse.c#L2986-L2994

Updated by nobu (Nobuyoshi Nakada) 5 months ago

  • Status changed from Open to Feedback

You may want to re-define Warning.warn.

Updated by Earlopain (Earlopain _) 5 months ago

nobu (Nobuyoshi Nakada) wrote in #note-1:

You may want to re-define Warning.warn.

Thank you, that works. Apologies for the wrong report.

Actions

Also available in: Atom PDF

Like0
Like0Like0