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

···

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

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

--
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

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.

···

On Tue, Dec 31, 2013 at 2:52 PM, <HANSEM1@nationwide.com> wrote:

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

--
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 Lambert :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 Nakada <nobu@ruby-lang.org>

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

-- Thierry

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

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

Abinoam Jr.

···

On Wed, Jan 1, 2014 at 11:02 AM, Thierry Lambert <lists@ruby-forum.com> wrote:

Abinoam Jr. wrote in post #1131925:

Can you confirm this Thierry Hansem?

It's Thierry Lambert :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 Nakada <nobu@ruby-lang.org>

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

-- Thierry

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