ruby-changes:59818
From: Nobuyoshi <ko1@a...>
Date: Mon, 27 Jan 2020 16:22:14 +0900 (JST)
Subject: [ruby-changes:59818] 1ddc719a56 (master): Check the encoding of `half:` option
https://git.ruby-lang.org/ruby.git/commit/?id=1ddc719a56 From 1ddc719a562b1ee4c3ae6cf4d1f6c386e142b087 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 27 Jan 2020 16:12:15 +0900 Subject: Check the encoding of `half:` option diff --git a/numeric.c b/numeric.c index 2471f9b..c880199 100644 --- a/numeric.c +++ b/numeric.c @@ -233,6 +233,7 @@ rb_num_get_rounding_option(VALUE opts) https://github.com/ruby/ruby/blob/trunk/numeric.c#L233 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: diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 7cbf3b5..a94bbce 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -764,6 +764,9 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L764 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/