Skip to content

Never change the underlying string encoding #132

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ext/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) {
public IRubyObject binmode(ThreadContext context) {
StringIOData ptr = this.getPtr();
ptr.enc = EncodingUtils.ascii8bitEncoding(context.runtime);
if (writable()) ptr.string.setEncoding(ptr.enc);

return this;
}
Expand Down Expand Up @@ -1809,10 +1808,6 @@ public IRubyObject set_encoding(ThreadContext context, IRubyObject ext_enc) {

// in read-only mode, StringIO#set_encoding no longer sets the encoding
RubyString string = ptr.string;
if (string != null && writable() && string.getEncoding() != enc) {
string.modify();
string.setEncoding(enc);
}
} finally {
if (locked) unlock(ptr);
}
Expand Down Expand Up @@ -1847,9 +1842,6 @@ public IRubyObject set_encoding_by_bom(ThreadContext context) {
private Encoding setEncodingByBOM(ThreadContext context, StringIOData ptr) {
Encoding enc = detectBOM(context, ptr.string, (ctx, enc2, bomlen) -> {
ptr.pos = bomlen;
if (writable()) {
ptr.string.setEncoding(enc2);
}
return enc2;
});
ptr.enc = enc;
Expand Down
9 changes: 0 additions & 9 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ set_encoding_by_bom(struct StringIO *ptr)
if (idx) {
extenc = rb_enc_from_index(idx);
ptr->pos = bomlen;
if (ptr->flags & FMODE_WRITABLE) {
rb_enc_associate_index(ptr->string, idx);
}
}
ptr->enc = extenc;
return extenc;
Expand Down Expand Up @@ -696,9 +693,6 @@ strio_binmode(VALUE self)
rb_encoding *enc = rb_ascii8bit_encoding();

ptr->enc = enc;
if (WRITABLE(self)) {
rb_enc_associate(ptr->string, enc);
}
return self;
}

Expand Down Expand Up @@ -1859,9 +1853,6 @@ strio_set_encoding(int argc, VALUE *argv, VALUE self)
}
}
ptr->enc = enc;
if (!NIL_P(ptr->string) && WRITABLE(self)) {
rb_enc_associate(ptr->string, enc);
}

return self;
}
Expand Down
2 changes: 1 addition & 1 deletion test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def test_set_encoding
f = StringIO.new()
f.set_encoding("ISO-8859-16:ISO-8859-1")
assert_equal(Encoding::ISO_8859_16, f.external_encoding)
assert_equal(Encoding::ISO_8859_16, f.string.encoding)
assert_equal(Encoding::UTF_8, f.string.encoding)
assert_nil(f.internal_encoding)
end

Expand Down