diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | error.c | 2 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 12 |
3 files changed, 19 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Wed Sep 28 00:21:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * error.c (rb_warning_s_warn): the argument must be an + ASCII-compatible string. [ruby-core:77430] [Bug #12793] + Tue Sep 27 23:22:31 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * parse.y (symbol, dsym, parser_set_number_literal): set state to @@ -152,6 +152,8 @@ ruby_only_for_internal_use(const char *func) static VALUE rb_warning_s_warn(VALUE mod, VALUE str) { + Check_Type(str, T_STRING); + rb_must_asciicompat(str); rb_write_error_str(str); return Qnil; } diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 3735e492d8..91d3ac1e93 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -940,4 +940,16 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| remove_method :warn2 end end + + def test_warning_warn_invalid_argument + assert_raise(TypeError) do + ::Warning.warn nil + end + assert_raise(TypeError) do + ::Warning.warn 1 + end + assert_raise(Encoding::CompatibilityError) do + ::Warning.warn "\x00a\x00b\x00c".force_encoding("utf-16be") + end + end end |