Bug #8133
closed
Regexp macro %r{} is loosing backslash on "\}"
Added by jstribny (Josef Stribny) over 11 years ago.
Updated over 11 years ago.
Description
Hello,
Ruby 2.0.0 is loosing the backslash when used on "}" string (exact match).
How to reproduce in irb:
2.0.0-p0 :003 > %r{}}
=> /}/
2.0.0-p0 :004 > %r{{}
=> /{/
Compared to:
1.9.3p392 :001 > %r{{}
=> /{/
1.9.3p392 :002 > %r{}}
=> /}/
This shouldn't probably happen.
- Status changed from Open to Rejected
There is nothing different, as '}' is not a regexp meta character.
- Status changed from Rejected to Open
It doesn't look to be issue of regexp but issue of parser:
C:\Projects>irb
irb(main):001:0> a = %r|}|
=> /}/
irb(main):002:0> b = %r{}}
=> /}/
irb(main):003:0> a == b
=> false
a and b are apparently not the same. They used to be the same in Ruby 1.9.3.
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r39858.
Josef, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
parse.y: escape all closing parens
- parse.y (simple_re_meta): escape all closing characters, not only
round parenthesis. [ruby-core:53578] [Bug #8133]
nobu (Nobuyoshi Nakada) wrote:
This issue was solved with changeset r39858.
Thank you.
Just for information: r39858 introduces the behavior change.
Whether %r{n{3}}} matches with:
| "nnn}" | "n{3}}"
----------+--------+---------
1.9.3p392 | YES | NO
2.0.0p0 | NO | YES
trunk | YES | NO
--
Yusuke Endoh mame@tsg.ne.jp
Hmm, is it a bug introduced in 2.0.0?
I personally feel the behavior of 2.0.0 is natural.
nagachika (Tomoyuki Chikanaga) wrote:
Hmm, is it a bug introduced in 2.0.0?
I personally feel the behavior of 2.0.0 is natural.
} in this case doesn't escape a regexp meta character, it escapes closing terminator of %r{...} literal.
mame (Yusuke Endoh) wrote:
Just for information: r39858 introduces the behavior change.
Whether %r{n{3}}} matches with:
| "nnn}" | "n{3}}"
----------+--------+---------
1.9.3p392 | YES | NO
2.0.0p0 | NO | YES
trunk | YES | NO
On my environment the result was exactly opposite.
$ cat regexp_test.rb
re = %r{n{3}}}
p re
p [re =~ "nnn}", re =~ "n{3}}"]
ruby 1.9.3dev (2011-09-24 revision 33322) [x86_64-darwin10.8.0]
/n{3}}/
[nil, 0]
ruby 2.0.0p96 (2013-03-25 revision 39918) [x86_64-darwin10.8.0]
/n{3}}/
[0, nil]
ruby 2.1.0dev (2013-03-24 trunk 39908) [x86_64-darwin10.8.0]
/n{3}}/
[nil, 0]
naruse (Yui NARUSE) wrote:
} in this case doesn't escape a regexp meta character, it escapes closing terminator of %r{...} literal.
I agree. It's reasonable.
Thanks.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0