ruby-changes:17139
From: nobu <ko1@a...>
Date: Sun, 29 Aug 2010 23:25:37 +0900 (JST)
Subject: [ruby-changes:17139] Ruby:r29139 (trunk): * file.c (rb_get_path_check): clarify error message for
nobu 2010-08-29 23:25:23 +0900 (Sun, 29 Aug 2010) New Revision: 29139 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29139 Log: * file.c (rb_get_path_check): clarify error message for ASCII-incompatible path name. Modified files: trunk/ChangeLog trunk/file.c trunk/test/ruby/test_path.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29138) +++ ChangeLog (revision 29139) @@ -1,3 +1,8 @@ +Sun Aug 29 23:25:18 2010 Nobuyoshi Nakada <nobu@r...> + + * file.c (rb_get_path_check): clarify error message for + ASCII-incompatible path name. + Sun Aug 29 16:02:54 2010 NARUSE, Yui <naruse@r...> * common.mk (node_name.inc): remove command option -n and give Index: test/ruby/test_path.rb =================================================================== --- test/ruby/test_path.rb (revision 29138) +++ test/ruby/test_path.rb (revision 29139) @@ -239,4 +239,12 @@ 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 Index: file.c =================================================================== --- file.c (revision 29138) +++ file.c (revision 29139) @@ -148,6 +148,7 @@ { VALUE tmp; ID to_path; + rb_encoding *enc; if (insecure_obj_p(obj, level)) { rb_insecure_operation(); @@ -161,11 +162,15 @@ 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/