aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_exception.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-08 09:08:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-08 09:08:31 +0000
commit50784a0a4412df551d96dd01067473cd4226481b (patch)
treeac31564d8efa9913bc4b25bc1e099916d89f140d /test/ruby/test_exception.rb
parente52b102c36dc1dd609a97149e99edc7d1f96b7a4 (diff)
downloadruby-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/ruby/test_exception.rb')
-rw-r--r--test/ruby/test_exception.rb37
1 files changed, 37 insertions, 0 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