[ruby-core:126850] [Ruby Bug#22381] MatchData assigned to $~ is incorrectly reused
Issue #22381 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #22381: MatchData assigned to $~ is incorrectly reused https://bugs.ruby-lang.org/issues/22381 * Author: jhawthorn (John Hawthorn) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ```ruby m = /a/.match("a").dup # dup a MatchData (has no "busy" flag set) $~ = m # assign to $~ /b/ =~ "b" # perform an 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 -- https://bugs.ruby-lang.org/
Issue #22381 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED to 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE ruby_4_0 commit:f980c9475bf0b206f219d5ebc3f8164582194553. https://github.com/ruby/ruby/pull/19171 ---------------------------------------- Bug #22381: MatchData assigned to $~ is incorrectly reused https://bugs.ruby-lang.org/issues/22381#change-119431 * Author: jhawthorn (John Hawthorn) * Status: Closed * Backport: 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE ---------------------------------------- ```ruby 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 -- https://bugs.ruby-lang.org/
participants (2)
-
jhawthorn (John Hawthorn) -
k0kubun (Takashi Kokubun)