Skip to content

Commit acaaa6e

Browse files
committed
Fix ascii_only? flag in strio_write
1 parent 824d2f6 commit acaaa6e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ext/stringio/stringio.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,9 +915,6 @@ strio_extend(struct StringIO *ptr, long pos, long len)
915915
if (pos > olen)
916916
MEMZERO(RSTRING_PTR(ptr->string) + olen, char, pos - olen);
917917
}
918-
else {
919-
rb_str_modify(ptr->string);
920-
}
921918
}
922919

923920
/*
@@ -1465,6 +1462,7 @@ strio_write(VALUE self, VALUE str)
14651462
}
14661463
else {
14671464
strio_extend(ptr, ptr->pos, len);
1465+
rb_str_modify(ptr->string);
14681466
memmove(RSTRING_PTR(ptr->string)+ptr->pos, RSTRING_PTR(str), len);
14691467
}
14701468
RB_GC_GUARD(str);

test/stringio/test_stringio.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,16 @@ def test_encoding_write
922922
assert_equal("abc".encode("utf-32be"), s.string)
923923
end
924924

925+
def test_write_str_modify
926+
seek_pos = [0, 2, 4, 6]
927+
seek_pos.each do |pos|
928+
s = StringIO.new('abcd')
929+
s.seek(pos)
930+
s.write("\xff\xff\xff")
931+
refute_predicate(s.string, :ascii_only?)
932+
end
933+
end
934+
925935
def test_encoding_read
926936
s = StringIO.new("abc".encode("utf-32be"), "r:utf-8")
927937
assert_equal("\0\0\0a\0\0\0b\0\0\0c", s.read)

0 commit comments

Comments
 (0)