From: shugo@... Date: 2015-12-17T22:05:54+00:00 Subject: [ruby-core:72224] [Ruby trunk - Bug #11827] StringIO with set_encoding broken with enabled frozen string literal Issue #11827 has been updated by Shugo Maeda. Yui NARUSE wrote: > Away from the case and thinking ideal behavior, StringIO should be a view of given source string and set_encoding shouldn't change source encoding. > But I'm not sure that it is worth breaking the compatibility. FYI, nobu figured out that open-uri depends on the current behavior: ```ruby enc = Encoding::ASCII_8BIT unless enc if self.respond_to? :force_encoding self.force_encoding(enc) elsif self.respond_to? :string self.string.force_encoding(enc) else # Tempfile self.set_encoding enc end end ``` ---------------------------------------- Bug #11827: StringIO with set_encoding broken with enabled frozen string literal https://bugs.ruby-lang.org/issues/11827#change-55633 * Author: deepj # * Status: Feedback * Priority: Normal * Assignee: * ruby -v: ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-darwin15] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- I'm not sure if this the following problem is an expected behavior. But I guess, it is a bug when I run the code below. It throws `set_encoding': can't modify frozen String (RuntimeError). ~~~ # frozen_string_literal: true io = StringIO.new('') io.set_encoding(Encoding::BINARY) ~~~ I wouldn't expect this kind of behavior. -- https://bugs.ruby-lang.org/