Project

General

Profile

Actions

Bug #22381

open

MatchData assigned to $~ is incorrectly reused

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

Added by jhawthorn (John Hawthorn) about 14 hours ago. Updated about 14 hours ago.

Status:
Open
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

Actions

Also available in: PDF Atom