Project

General

Profile

Actions

Bug #20246

closed

Unexpected behavior for Regexp in Subexpression Calls on Ruby 3.3.0

Added by bestwebua (Vladislav Trotsenko) 3 months ago. Updated about 1 month ago.

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

Description

Hello! A few days ago, after migration on 3.3.0 I have faced with issue inside subexpression calls.

An expected result on Ruby up to 3.3.0:

'1.2.3'[/(\d+)(\.\g<1>){2}/] # => "1.2.3"

An actual result on Ruby 3.3.0:

'1.2.3'[/(\d+)(\.\g<1>){2}/] # => nil

Updated by make_now_just (Hiroya Fujinami) 3 months ago

This is a bug in regex optimization.

Some optimizations have been disabled for memoization since 3.3.0. Therefore, another optimization was enabled, and that bug has surfaced.

By complicating the content of the first loop, we can confirm that the same problem occurs in 3.2 and earlier.

$ ruby --version
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin22]
$ ruby -e 'p "1.2.3"[/((?:\d|foo|bar)+)(\.\g<1>){2}/]'
nil

#9897 will fix this bug.

Actions #2

Updated by naruse (Yui NARUSE) 3 months ago

  • 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 #3

Updated by make_now_just (Hiroya Fujinami) 3 months ago

  • Status changed from Open to Closed

Applied in changeset git|4a6384ed9358e8fb8464f6e37efb5477182f01db.


Fix [Bug #20246]: Don't set next_head_exact if a capture is called (#9897)

Updated by naruse (Yui NARUSE) about 1 month ago

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

ruby_3_3 05787897f69087abdabee926971cdf364bd73730 merged revision(s) 18ee7c9a108bf3424814565377c8796e5e455cf7,4a6384ed9358e8fb8464f6e37efb5477182f01db.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0