Add rb_str_resize coderange test

This commit is contained in:
tompng 2024-01-17 01:16:31 +09:00 committed by Jean Boussier
parent 9c7374b0e6
commit 04467218ce
2 changed files with 26 additions and 0 deletions

View File

@ -16,9 +16,17 @@ bug_str_append(VALUE str, VALUE addendum)
return str;
}
static VALUE
bug_str_resize(VALUE str, VALUE len)
{
rb_str_resize(str, NUM2LONG(len));
return str;
}
void
Init_string_set_len(VALUE klass)
{
rb_define_method(klass, "set_len", bug_str_set_len, 1);
rb_define_method(klass, "append", bug_str_append, 1);
rb_define_method(klass, "resize", bug_str_resize, 1);
}

View File

@ -63,4 +63,22 @@ class Test_StrSetLen < Test::Unit::TestCase
assert_not_predicate str, :ascii_only?
assert_equal u, str
end
def test_valid_encoding_after_resized
s = "\0\0".force_encoding(Encoding::UTF_16BE)
str = Bug::String.new(s)
assert_predicate str, :valid_encoding?
str.resize(1)
assert_not_predicate str, :valid_encoding?
str.resize(2)
assert_predicate str, :valid_encoding?
str.resize(3)
assert_not_predicate str, :valid_encoding?
s = "\xDB\x00\xDC\x00".force_encoding(Encoding::UTF_16BE)
str = Bug::String.new(s)
assert_predicate str, :valid_encoding?
str.resize(2)
assert_not_predicate str, :valid_encoding?
end
end