Project

General

Profile

Actions

Bug #22381

closed

MatchData assigned to $~ is incorrectly reused

Bug #22381: MatchData assigned to $~ is incorrectly reused

Added by jhawthorn (John Hawthorn) 3 days ago. Updated 1 day ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:126850]

Description

m = /a/.match("a").dup # dup a MatchData (has no "busy" flag set)
$~ = m # assign to $~
/b/ =~ "b" # perform a match that sets $~
p m
# "b" on Ruby 4.0 (and 1.8-2.7, incorrect)
# "a" on Ruby 3.0-3.4 (correct)

This is because the MATCH_BUSY flag isn't set correct and so the implicit match reuse (removed in #17507, re-added in #20652) mutates this escaped value

Updated by jhawthorn (John Hawthorn) 3 days ago Actions #1

  • Description updated (diff)

Updated by jhawthorn (John Hawthorn) 3 days ago Actions #2

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED

Updated by jhawthorn (John Hawthorn) 1 day ago Actions #3

  • Status changed from Open to Closed

Applied in changeset git|ea3cd7efe1f6bab78572b31774462e891ef01243.


Fix reuse of MatchData assigned to $~

$~ = m = /a/.match("a").dup
/b/ =~ "b"
p m

[Bug #22381]

Actions

Also available in: PDF Atom