Skip to content

Commit

Permalink
Fix ascii_only? flag in strio_write
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 15, 2024
1 parent 824d2f6 commit ada1ece
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,9 +915,6 @@ strio_extend(struct StringIO *ptr, long pos, long len)
if (pos > olen)
MEMZERO(RSTRING_PTR(ptr->string) + olen, char, pos - olen);
}
else {
rb_str_modify(ptr->string);
}
}

/*
Expand Down Expand Up @@ -1465,6 +1462,7 @@ strio_write(VALUE self, VALUE str)
}
else {
strio_extend(ptr, ptr->pos, len);
rb_str_modify(ptr->string);
memmove(RSTRING_PTR(ptr->string)+ptr->pos, RSTRING_PTR(str), len);
}
RB_GC_GUARD(str);
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 @@ -922,6 +922,16 @@ def test_encoding_write
assert_equal("abc".encode("utf-32be"), s.string)
end

def test_write_str_modify
seek_pos = [0, 2, 4, 6]
seek_pos.each do |pos|
s = StringIO.new('abcd')
s.seek(pos)
s.write("\xff\xff\xff")
refute(s.string.ascii_only?)
end
end

def test_encoding_read
s = StringIO.new("abc".encode("utf-32be"), "r:utf-8")
assert_equal("\0\0\0a\0\0\0b\0\0\0c", s.read)
Expand Down

0 comments on commit ada1ece

Please sign in to comment.