Skip to content
Merged
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
6 changes: 6 additions & 0 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,14 @@ strio_write(VALUE self, VALUE str)
}
}
else {
int cr0 = ENC_CODERANGE(ptr->string);
int cr = ENC_CODERANGE_UNKNOWN;
if (rb_enc_asciicompat(enc) && rb_enc_asciicompat(enc2)) {
cr = ENC_CODERANGE_AND(cr0, ENC_CODERANGE(str));
}
strio_extend(ptr, ptr->pos, len);
memmove(RSTRING_PTR(ptr->string)+ptr->pos, RSTRING_PTR(str), len);
if (cr != cr0) ENC_CODERANGE_SET(ptr->string, cr);
}
RB_GC_GUARD(str);
ptr->pos += len;
Expand Down
10 changes: 10 additions & 0 deletions test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,16 @@ def test_binary_encoding_read_and_default_internal
$VERBOSE = verbose
end

def test_coderange_after_overwrite
s = StringIO.new("".b)

s.write("a=b&c=d")
s.rewind
assert_predicate(s.string, :ascii_only?)
s.write "\u{431 43e 433 443 441}"
assert_not_predicate(s.string, :ascii_only?)
end

def assert_string(content, encoding, str, mesg = nil)
assert_equal([content, encoding], [str, str.encoding], mesg)
end
Expand Down