Nested repeat operator & instance_eval

Hi,

I get a strange behavior from instance_eval when reporting warnings on
regular expressions, both in 1.9.3p448 and 2.0.0p353.

The file “test.rb” contains:

$-w = 2
file = ‘foo.rb’
code = <<-RUBY
x = /]]/
y = /[a-z]+*/
RUBY
instance_eval code, file

When run, I get:
foo.rb:1: warning: regular expression has ‘]’ without escape: /]]/
test.rb:7: warning: nested repeat operator + and * was replaced with
'’: /[a-z]+/

The second warning not reported as “foo.rb:2”: am I missing something,
or should I report a bug?

– Thierry

I think Hansem is finding strange not the warning per si but the file
and line number indication.

Why the first warning is on foo.rb:1 and the second warning is on
test.rb:7 ?

Can you confirm this Thierry Hansem?

Abinoam Jr.

x = /]]/
or should I report a bug?

– Thierry


Posted via http://www.ruby-forum.com/.

I don’t believe it’s a bug in instance_eval, I get similar output just
running in irb.

irb(main):019:0> x = /]]/
(irb):19: warning: regular expression has ‘]’ without escape: /]]/
=> /]]/
irb(main):020:0> y = /[a-z]+/
C:/Ruby193/lib/ruby/1.9.1/irb/workspace.rb:80: warning: nested repeat
operator +
and * was replaced with '
’: /[a-z]+/
=> /[a-z]+
/
irb(main):021:0>

Michael Hansen

Abinoam Jr. wrote in post #1131925:

Can you confirm this Thierry Hansem?

It’s Thierry L. :slight_smile:

Yes, the problem lies in the origin of the message, i.e. in the
backtrace. I suspect it’s a problem that has already been seen, as the
ruby ChangeLog contains:

Mon Nov 29 22:55:24 2010 Nobuyoshi N. [email protected]

  • lib/uri/common.rb (URI::WFKV_): get rid of backtrack explosion
    by nested repeat operators. [ruby-core:33464]

– Thierry

:slight_smile:
Heheh Sorry Thierry LAMBERT!!!
I was fast to answer and mixed the names. Sorry.

Abinoam Jr.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs