Project

General

Profile

Bug #9728

Regexp bug

Added by sawa (Tsuyoshi Sawada) about 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
Ruby 2.0
[ruby-core:61959]

Description

As reported in StackOverflow (http://stackoverflow.com/questions/23004527) (with a wrong expectation), the following regex pattern with the * operator does not match.

"ab" =~ /(?!^a).*b/
# => nil

When ? is used instead, it seems to match correctly:

"ab" =~ /(?!^a).?b/
# => 1

According to the original reporter of the linked site, this does not happen in Ruby 1.9.3.

Associated revisions

Revision 4855b79e
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

merge r47598 partially. extracted commits are as follows. [Bug #9728]
https://github.com/k-takata/Onigmo/commit/15ddec6d18e27fdc1988236764e766fd5892ecf5

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 7e344b0b
Added by usa (Usaku NAKAMURA) over 4 years ago

  • regcomp.c, regexec.c: Optimization should be disabled not only for /(?<=x)./ but also for /(?!x)./. (merge r47598 partially. [Bug #9728])

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 47976
Added by usa (Usaku NAKAMURA) over 4 years ago

  • regcomp.c, regexec.c: Optimization should be disabled not only for /(?<=x)./ but also for /(?!x)./. (merge r47598 partially. [Bug #9728])

History

Updated by phasis68 (Heesob Park) about 5 years ago

I found this issue is related with the ONIG_DONT_OPTIMIZE macro.

If I insert "#define ONIG_DONT_OPTIMIZE" in regint.h, the regexp works like Ruby 1.9.3.

before define:

C:\work\ruby-2.2.0-r45349>miniruby -ve 'p "ab"=~/(?!^a).*b/;'
ruby 2.2.0dev (2014-03-16 trunk 45349) [x64-mswin64_120]
nil

after define:

C:\work\ruby-2.2.0-r45349>miniruby -ve 'p "ab"=~/(?!^a).*b/;'
ruby 2.2.0dev (2014-03-16 trunk 45349) [x64-mswin64_120]
1

Updated by k_takata (Ken Takata) over 4 years ago

This bug is fixed with the following Onigmo's commit:
https://github.com/k-takata/Onigmo/commit/15ddec6d18e27fdc1988236764e766fd5892ecf5
This fix is included in Onigmo 5.15.0.

Updated by k_takata (Ken Takata) over 4 years ago

  • Status changed from Open to Closed

Fixed with r47598.

Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE

partially backport r47598 into ruby_2_1 branch at r47954.

Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE

Backported into ruby_2_0_0 at r47976.

Also available in: Atom PDF