Bug #8133

Regexp macro %r{} is loosing backslash on "\}"

Added by Josef Stribny about 1 year ago. Updated about 1 year ago.

[ruby-core:53578]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:2.1.0
ruby -v:2.0.0 Backport:

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.


Related issues

Related to ruby-trunk - Bug #7610: Incompatible with percent literal regexp between 1.9.3 an... Closed 12/23/2012
Duplicated by Backport200 - Backport #8135: Backport escape all closing parens - r39858 (Regexp macro... Closed 03/21/2013

Associated revisions

Revision 39858
Added by Nobuyoshi Nakada about 1 year ago

parse.y: escape all closing parens

  • parse.y (simpleremeta): escape all closing characters, not only round parenthesis. [Bug #8133]

History

#1 Updated by Nobuyoshi Nakada about 1 year ago

  • Status changed from Open to Rejected

There is nothing different, as '}' is not a regexp meta character.

#2 Updated by Vit Ondruch about 1 year ago

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

#3 Updated by Nobuyoshi Nakada about 1 year ago

  • 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 (simpleremeta): escape all closing characters, not only round parenthesis. [Bug #8133]

#4 Updated by Vit Ondruch about 1 year ago

nobu (Nobuyoshi Nakada) wrote:

This issue was solved with changeset r39858.

Thank you.

#5 Updated by Yusuke Endoh about 1 year ago

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

#6 Updated by Tomoyuki Chikanaga about 1 year ago

Hmm, is it a bug introduced in 2.0.0?
I personally feel the behavior of 2.0.0 is natural.

#7 Updated by Yui NARUSE about 1 year ago

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.

#8 Updated by Tomoyuki Chikanaga about 1 year ago

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]

#9 Updated by Tomoyuki Chikanaga about 1 year ago

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