summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2024-01-18 12:42:15 +0900
committergit <[email protected]>2024-01-18 03:42:21 +0000
commitfd1bafc11f74cb2bb74bf97bcba4ef694a533aec (patch)
treea66d030d6a8d72e9ad780f3deddd3b792b32df5a /test
parent4095191f2c037a665353caf8824c7f5eef67efe4 (diff)
[ruby/stringio] Fix ascii_only? flag in strio_write
(https://github.com/ruby/stringio/pull/77) Followup of #79 `rb_str_resize()` was changed by https://github.com/ruby/ruby/commit/b0b9f7201acab05c2a3ad92c3043a1f01df3e17f . ```c rb_str_resize(string, shorter) // clear ENC_CODERANGE in some case rb_str_resize(string, longer) // does not clear ENC_CODERANGE anymore ``` ```c // rb_str_resize in string.c if (slen > len && ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) { ENC_CODERANGE_CLEAR(str); } ``` I think this change is based on an assumption that appending null bytes will not change flag `ascii_only?`. `strio_extend()` will make the string longer if needed, and update the flags correctly for appending null bytes. Before `memmove()`, we need to `rb_str_modify()` because updated flags are not updated for `memmove()`. https://github.com/ruby/stringio/commit/b31a538576
Diffstat (limited to 'test')
-rw-r--r--test/stringio/test_stringio.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 15fcc21146..8afbcf3545 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -961,6 +961,12 @@ class TestStringIO < Test::Unit::TestCase
assert_predicate(s.string, :ascii_only?)
s.write "\u{431 43e 433 443 441}"
assert_not_predicate(s.string, :ascii_only?)
+
+ s = StringIO.new("\u{3042}")
+ s.rewind
+ assert_not_predicate(s.string, :ascii_only?)
+ s.write('aaaa')
+ assert_predicate(s.string, :ascii_only?)
end
def assert_string(content, encoding, str, mesg = nil)