[ruby-core:84530] [Ruby trunk Bug#14251] String insert changing value of other string

From: ricardovsilva@...
Date: 2017-12-27 22:29:01 UTC
List: ruby-core #84530
Issue #14251 has been reported by ricardovsilva (Ricardo Silva).

----------------------------------------
Bug #14251: String insert changing value of other string
https://bugs.ruby-lang.org/issues/14251

* Author: ricardovsilva (Ricardo Silva)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
~~~ ruby
foo = 'abc'
bar = foo
bar.insert(1, d)

puts foo 'adbc'
puts bar 'adbc'
~~~

The example above should only affect bar variable. It leads to an error by programmer.

A bypass that I found is to do:

~~~ ruby
foo = 'aaa'
bar = String.new foo
bar.insert(1, 'd')
puts foo #aaa
puts bar #adaa
~~~





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next