diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-25 18:43:58 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-25 18:43:58 +0000 |
commit | ddfcb969300604b1f03887e2498779c7c879ca96 (patch) | |
tree | 463d3b2620a76fe33cd7f2274fa84f18697dde09 | |
parent | f77d40235275c80a4e1771b55a9d2c86bf129b26 (diff) |
safe.c: preserve encoding
* safe.c (rb_secure): preserve encoding of the called method name
in error messages.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | safe.c | 4 | ||||
-rw-r--r-- | test/ruby/test_dir.rb | 17 |
2 files changed, 19 insertions, 2 deletions
@@ -90,8 +90,8 @@ rb_secure(int level) if (level <= rb_safe_level()) { ID caller_name = rb_frame_callee(); if (caller_name) { - rb_raise(rb_eSecurityError, "Insecure operation `%s' at level %d", - rb_id2name(caller_name), rb_safe_level()); + rb_raise(rb_eSecurityError, "Insecure operation `%"PRIsVALUE"' at level %d", + rb_id2str(caller_name), rb_safe_level()); } else { rb_raise(rb_eSecurityError, "Insecure operation at level %d", diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index ee1210cc37..03c62da547 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -304,4 +304,21 @@ class TestDir < Test::Unit::TestCase end } end + + def test_insecure_chdir + assert_raise(SecurityError) do + proc do + $SAFE=3 + Dir.chdir("/") + end.call + end + m = "\u{79fb 52d5}" + d = Class.new(Dir) {singleton_class.class_eval {alias_method m, :chdir}} + assert_raise_with_message(SecurityError, /#{m}/) do + proc do + $SAFE=3 + d.__send__(m, "/") + end.call + end + end end |