1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Check the encoding of half: option

This commit is contained in:
Nobuyoshi Nakada 2020-01-27 16:12:15 +09:00
parent af899503a6
commit 1ddc719a56
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 4 additions and 0 deletions

View file

@ -233,6 +233,7 @@ rb_num_get_rounding_option(VALUE opts)
str = rb_check_string_type(rounding);
if (NIL_P(str)) goto invalid;
}
rb_must_asciicompat(str);
s = RSTRING_PTR(str);
switch (RSTRING_LEN(str)) {
case 2:

View file

@ -764,6 +764,9 @@ class TestFloat < Test::Unit::TestCase
assert_raise_with_message(ArgumentError, /xxx/) {
1.0.round(half: "\0xxx")
}
assert_raise_with_message(Encoding::CompatibilityError, /ASCII incompatible/) {
1.0.round(half: "up".force_encoding("utf-16be"))
}
end
def test_Float