diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-08 09:08:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-08 09:08:31 +0000 |
commit | 50784a0a4412df551d96dd01067473cd4226481b (patch) | |
tree | ac31564d8efa9913bc4b25bc1e099916d89f140d /test | |
parent | e52b102c36dc1dd609a97149e99edc7d1f96b7a4 (diff) | |
download | ruby-50784a0a4412df551d96dd01067473cd4226481b.tar.gz |
Defer escaping control char in error messages
* eval_error.c (print_errinfo): defer escaping control char in
error messages until writing to stderr, instead of quoting at
building the message. [ruby-core:90853] [Bug #15497]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_exception.rb | 37 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 2 |
3 files changed, 38 insertions, 9 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 05c74f6dcd..cabd20c0e8 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1071,6 +1071,43 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end; end + def assert_null_char(src, *args, **opts) + begin + eval(src) + rescue => e + end + assert_not_nil(e) + assert_include(e.message, "\0") + assert_in_out_err([], src, [], [], *args, **opts) do |_, err,| + err.each do |e| + assert_not_include(e, "\0") + end + end + e + end + + def test_control_in_message + bug7574 = '[ruby-dev:46749]' + assert_null_char("#{<<~"begin;"}\n#{<<~'end;'}", bug7574) + begin; + Object.const_defined?("String\0") + end; + assert_null_char("#{<<~"begin;"}\n#{<<~'end;'}", bug7574) + begin; + Object.const_get("String\0") + end; + end + + def test_encoding_in_message + name = "\u{e9}t\u{e9}" + e = EnvUtil.with_default_external("US-ASCII") do + assert_raise(NameError) do + Object.const_get(name) + end + end + assert_include(e.message, name) + end + def test_method_missing_reason_clear bug10969 = '[ruby-core:68515] [Bug #10969]' a = Class.new {def method_missing(*) super end}.new diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 4ca0e09277..bac16f2bda 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -745,10 +745,6 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c1.const_get(:foo) } bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_get(1) } - bug7574 = '[ruby-dev:46749]' - assert_raise_with_message(NameError, "wrong constant name \"String\\u0000\"", bug7574) { - Object.const_get("String\0") - } end def test_const_defined_invalid_name @@ -756,10 +752,6 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c1.const_defined?(:foo) } bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_defined?(1) } - bug7574 = '[ruby-dev:46749]' - assert_raise_with_message(NameError, "wrong constant name \"String\\u0000\"", bug7574) { - Object.const_defined?("String\0") - } end def test_const_get_no_inherited diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 69521b1d23..d913e8b918 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -310,7 +310,7 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err(%W(-\r -e) + [""], "", [], []) - assert_in_out_err(%W(-\rx), "", [], /invalid option -\\x0D \(-h will show valid options\) \(RuntimeError\)/) + assert_in_out_err(%W(-\rx), "", [], /invalid option -\\r \(-h will show valid options\) \(RuntimeError\)/) assert_in_out_err(%W(-\x01), "", [], /invalid option -\\x01 \(-h will show valid options\) \(RuntimeError\)/) |