Project

General

Profile

This project is closed and read-only.

Actions

Bug #3147

closed

gsub evaluates the passed in replacement string making results unpredictable when replacement string is dynamically generated

Bug #3147: gsub evaluates the passed in replacement string making results unpredictable when replacement string is dynamically generated

Added by wwalker (Wayne Walker) over 16 years ago. Updated over 15 years ago.

Status:
Rejected
Assignee:
-
ruby -v:
ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-linux]
[ruby-core:29514]

Description

=begin
after the interpreter evaluates the replacement string (if it's a literal in "" or ''), gsub further evaluates it during execution changing the effective replacement string.

irb(main):016:0> a = 'Y'
=> "Y"
irb(main):017:0> b = 'Z\1'
=> "Z\1"
irb(main):018:0> c = '\\1'
=> "\\1"
irb(main):019:0> a.gsub(/(Y)/, b)
=> "ZY"
irb(main):020:0> a.gsub(/(Y)/, c)
=> "\1"

The last result is expected to be "\Y"
=end

Actions

Also available in: PDF Atom