From d2da9597c3b9f2dded80f53c16f4bf2c630e0ffe Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 29 Aug 2010 14:25:23 +0000 Subject: [PATCH] * file.c (rb_get_path_check): clarify error message for ASCII-incompatible path name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ file.c | 9 +++++++-- test/ruby/test_path.rb | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a26f15ff27..47b7eeeb8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Aug 29 23:25:18 2010 Nobuyoshi Nakada + + * file.c (rb_get_path_check): clarify error message for + ASCII-incompatible path name. + Sun Aug 29 16:02:54 2010 NARUSE, Yui * common.mk (node_name.inc): remove command option -n and give diff --git a/file.c b/file.c index 8da764a4c2..9f04b5f838 100644 --- a/file.c +++ b/file.c @@ -148,6 +148,7 @@ rb_get_path_check(VALUE obj, int level) { VALUE tmp; ID to_path; + rb_encoding *enc; if (insecure_obj_p(obj, level)) { rb_insecure_operation(); @@ -161,11 +162,15 @@ rb_get_path_check(VALUE obj, int level) StringValue(tmp); tmp = file_path_convert(tmp); - StringValueCStr(tmp); if (obj != tmp && insecure_obj_p(tmp, level)) { rb_insecure_operation(); } - rb_enc_check(tmp, rb_enc_from_encoding(rb_usascii_encoding())); + enc = rb_enc_get(tmp); + if (!rb_enc_asciicompat(enc)) { + tmp = rb_str_inspect(tmp); + rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %s", + rb_enc_name(enc), RSTRING_PTR(tmp)); + } return rb_str_new4(tmp); } diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb index 31c1885371..74d568ae49 100644 --- a/test/ruby/test_path.rb +++ b/test/ruby/test_path.rb @@ -239,4 +239,12 @@ class TestPath < Test::Unit::TestCase assert_equal('', File.extname('.x')) assert_equal('', File.extname('..x')) end + + def test_ascii_incompatible_path + s = "\u{221e}\u{2603}" + assert_raise(Encoding::CompatibilityError) {open(s.encode("utf-16be"))} + assert_raise(Encoding::CompatibilityError) {open(s.encode("utf-16le"))} + assert_raise(Encoding::CompatibilityError) {open(s.encode("utf-32be"))} + assert_raise(Encoding::CompatibilityError) {open(s.encode("utf-32le"))} + end end