Project

General

Profile

Actions

Bug #8133

closed

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

Added by jstribny (Josef Stribny) about 11 years ago. Updated about 11 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
2.0.0
Backport:
[ruby-core:53578]

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 2 (0 open2 closed)

Related to Ruby master - Bug #7610: Incompatible with percent literal regexp between 1.9.3 and 2.0.0Closed12/23/2012Actions
Has duplicate Backport200 - Backport #8135: Backport escape all closing parens - r39858 (Regexp macro %r{} is loosing backslash on "\}")Closednagachika (Tomoyuki Chikanaga)03/21/2013Actions

Updated by nobu (Nobuyoshi Nakada) about 11 years ago

  • Status changed from Open to Rejected

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

Updated by vo.x (Vit Ondruch) about 11 years 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.

Actions #3

Updated by nobu (Nobuyoshi Nakada) about 11 years 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 (simple_re_meta): escape all closing characters, not only
    round parenthesis. [ruby-core:53578] [Bug #8133]

Updated by vo.x (Vit Ondruch) about 11 years ago

nobu (Nobuyoshi Nakada) wrote:

This issue was solved with changeset r39858.

Thank you.

Updated by mame (Yusuke Endoh) about 11 years 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

Actions #6

Updated by nagachika (Tomoyuki Chikanaga) about 11 years ago

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

Updated by naruse (Yui NARUSE) about 11 years 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.

Updated by nagachika (Tomoyuki Chikanaga) about 11 years 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]

Updated by nagachika (Tomoyuki Chikanaga) about 11 years 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0