Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

String#[]= in 1.9 mode is not multibyte aware #1985

yob opened this Issue Nov 4, 2012 · 2 comments


None yet
3 participants

yob commented Nov 4, 2012

When I use String#[]= to replace part of a string in 1.9 mode, the string I'm inserting is truncated if it contains multi-byte UTF-8 characters.

⚡ rbx -v         
rubinius 2.0.0rc1 (1.8.7 release 2012-11-02 JI) [x86_64-unknown-linux-gnu]

⚡ cat foo.rb 
# coding: utf-8

haystack = "     "
needle   = "ápple"
haystack[Range.new(0, 5)] = needle
puts haystack

haystack = "     "
needle   = "ápple"
haystack[0,5] = needle
puts haystack

⚡ rbx -X19 foo.rb

⚡ rbx -X18 foo.rb

gkellogg commented Nov 6, 2012

I have a similar problem, expressed using the following example:

"\"Dürst\""[1..-2] => "D\xC3\xBCrst\""

Note that the final escaped " should not be there.

It only happens in 1.9 mode, seems okay in 1.8 mode.

yob commented Nov 26, 2012

I have another example of this

⚡ cat foo.rb 
# coding: utf-8

str_one = "写中国字"
puts str_one[-1..-1]
puts str_one[-1..-1].encoding


⚡ ruby1.9.1 -v
ruby 1.9.3p327 (2012-11-10) [x86_64-linux]

⚡ rbx -v
rubinius 2.0.0rc1 (1.9.3 bd640ab8 2012-11-02 JI) [x86_64-unknown-linux-gnu]


⚡ ruby1.9.1 foo.rb 

⚡ rbx foo.rb 

An exception occurred running foo.rb
    undefined method `encoding' on nil:NilClass. (NoMethodError)

  Kernel(NilClass)#encoding (method_missing) at kernel/delta/kernel.rb:81
        Object#__script__ at foo.rb:5
        Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:68
        Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:118
        Rubinius::Loader#script at kernel/loader.rb:614
        Rubinius::Loader#main at kernel/loader.rb:815

@brixen brixen closed this in 9019747 Nov 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment