Project

General

Profile

Actions

Bug #20098

closed

Wrong regexp match in ruby 3.2 and 3.3

Added by tompng (tomoya ishida) 12 months ago. Updated 9 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +MN [arm64-darwin22]
[ruby-core:115933]

Description

These regexp all matches in ruby 3.1.4, but not in ruby 3.3.0.

p /a((.|.)|bc){,4}z/.match? 'abcbcbcbcz'
p /a(b+?c*){4,5}z/.match? 'abbbccbbbccbcbcz' # matches in ruby 3.2.2
p /a(b+?(.|.)){2,3}z/.match? 'abbbcbbbcbbbcz'
p /a(b*?(.|.)[bc]){2,5}z/.match? 'abcbbbcbcccbcz'

Adding backref (to disable optimization) makes them match.

p /()\1a((.|.)|bc){,4}z/.match? 'abcbcbcbcz'
p /()\1a(b+?c*){4,5}z/.match? 'abbbccbbbccbcbcz'
p /()\1a(b+?(.|.)){2,3}z/.match? 'abbbcbbbcbbbcz'
p /()\1a(b*?(.|.)[bc]){2,5}z/.match? 'abcbbbcbcccbcz'

Found in this script https://gist.github.com/tompng/aa0706a181e9187bd79e8cec5a5f3c97

Updated by tompng (tomoya ishida) 12 months ago

Not same. https://bugs.ruby-lang.org/issues/20083 is fixed in master branch. This issue is found in a branch that fixes 20083.

Updated by weilandia (Nick Weiland) 10 months ago

Looks to be the same bug, but I cannot make it match with the backref. Below example matches in 3.2.2 but not in 3.3.0

str = "------------abcdefg------------#3895912"
re = /()\1\b\w*[a-zA-Z-]*\d+[\w-]{3,}\w+\b/
re.match?(str)
Actions #4

Updated by naruse (Yui NARUSE) 9 months ago

  • Status changed from Open to Closed
  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: REQUIRED
Actions #5

Updated by naruse (Yui NARUSE) 9 months ago

  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: REQUIRED to 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED

Updated by naruse (Yui NARUSE) 9 months ago

  • Backport changed from 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED to 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: DONE

ruby_3_3 7ae8abc23961bf4fa143a7a2cc0bc38167d468ae merged revision(s) bb59696614083660241ef272f222628cbfa95844.

Updated by nagachika (Tomoyuki Chikanaga) 9 months ago

The changeset bb59696614083660241ef272f222628cbfa95844 cannot be merged into ruby_3_2 branch cleanly and hard to me to write a patch. @tompng (tomoya ishida) Could you kindly create the patch for ruby_3_2 branch?

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0