ruby-changes:13246
From: nobu <ko1@a...>
Date: Sat, 19 Sep 2009 17:33:22 +0900 (JST)
Subject: [ruby-changes:13246] Ruby:r25007 (trunk): * dir.c (GlobPathValue), file.c (rb_get_path_check): path names
nobu 2009-09-19 17:33:01 +0900 (Sat, 19 Sep 2009) New Revision: 25007 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25007 Log: * dir.c (GlobPathValue), file.c (rb_get_path_check): path names must be ASCII compatible. Modified files: trunk/ChangeLog trunk/dir.c trunk/file.c trunk/test/ruby/test_dir.rb trunk/test/ruby/test_file_exhaustive.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 25006) +++ ChangeLog (revision 25007) @@ -1,3 +1,8 @@ +Sat Sep 19 17:32:59 2009 Nobuyoshi Nakada <nobu@r...> + + * dir.c (GlobPathValue), file.c (rb_get_path_check): path names + must be ASCII compatible. + Sat Sep 19 00:02:19 2009 Nobuyoshi Nakada <nobu@r...> * include/ruby/ruby.h (rb_type): forward declaration to suppress a Index: dir.c =================================================================== --- dir.c (revision 25006) +++ dir.c (revision 25007) @@ -343,7 +343,10 @@ /* can contain null bytes as separators */ \ (!RB_TYPE_P(str, T_STRING) ? \ FilePathValue(str) : \ - (safe) ? (rb_check_safe_obj(str), (str)) : (str)) + (check_safe_glob(str, safe), \ + check_glob_encoding(str), (str))) +#define check_safe_glob(str, safe) ((safe) ? rb_check_safe_obj(str) : (void)0) +#define check_glob_encoding(str) rb_enc_check((str), rb_enc_from_encoding(rb_usascii_encoding())) static VALUE dir_s_alloc(VALUE klass) Index: test/ruby/test_file_exhaustive.rb =================================================================== --- test/ruby/test_file_exhaustive.rb (revision 25006) +++ test/ruby/test_file_exhaustive.rb (revision 25007) @@ -3,6 +3,13 @@ require "tmpdir" class TestFileExhaustive < Test::Unit::TestCase + def assert_incompatible_encoding + d = "\u{3042}\u{3044}".encode("utf-16le") + assert_raise(Encoding::CompatibilityError) {yield d} + m = Class.new {define_method(:to_path) {d}} + assert_raise(Encoding::CompatibilityError) {yield m.new} + end + def setup @dir = Dir.mktmpdir("rubytest-file") File.chown(-1, Process.gid, @dir) @@ -388,6 +395,8 @@ assert_kind_of(String, File.expand_path("~")) assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") } assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha", "/") } + + assert_incompatible_encoding {|d| File.expand_path(d)} end def test_basename @@ -412,11 +421,14 @@ assert_equal(basename, File.basename(@file + ".", ".*")) assert_equal(basename, File.basename(@file + "::$DATA", ".*")) end + + assert_incompatible_encoding {|d| File.basename(d)} end def test_dirname assert(@file.start_with?(File.dirname(@file))) assert_equal(".", File.dirname("")) + assert_incompatible_encoding {|d| File.dirname(d)} end def test_extname @@ -440,6 +452,8 @@ end end end + + assert_incompatible_encoding {|d| File.extname(d)} end def test_split Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 25006) +++ test/ruby/test_dir.rb (revision 25007) @@ -161,6 +161,11 @@ Dir.glob(File.join(@root, '{\{\},a}'))) assert_equal([], Dir.glob(File.join(@root, '['))) assert_equal([], Dir.glob(File.join(@root, '[a-\\'))) + + d = "\u{3042}\u{3044}".encode("utf-16le") + assert_raise(Encoding::CompatibilityError) {Dir.glob(d)} + m = Class.new {define_method(:to_path) {d}} + assert_raise(Encoding::CompatibilityError) {Dir.glob(m.new)} end def test_foreach Index: file.c =================================================================== --- file.c (revision 25006) +++ file.c (revision 25007) @@ -127,6 +127,7 @@ if (obj != tmp && insecure_obj_p(tmp, level)) { rb_insecure_operation(); } + rb_enc_check(tmp, rb_enc_from_encoding(rb_usascii_encoding())); return rb_str_new4(tmp); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/