summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-19 08:33:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-19 08:33:01 +0000
commita1485dbea0024a5a263b40843f7af95e9c72925c (patch)
tree41ff49eb0653e30f6bc38db85622553228faf8c0
parentbdde51172cbf2754f6bbaa9e1678fbcc3d689dba (diff)
* dir.c (GlobPathValue), file.c (rb_get_path_check): path names
must be ASCII compatible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--dir.c5
-rw-r--r--file.c1
-rw-r--r--test/ruby/test_dir.rb5
-rw-r--r--test/ruby/test_file_exhaustive.rb14
5 files changed, 29 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index e6080477037..c93345a46fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Sep 19 17:32:59 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* include/ruby/ruby.h (rb_type): forward declaration to suppress a
diff --git a/dir.c b/dir.c
index 293386349eb..a71f5825fd8 100644
--- a/dir.c
+++ b/dir.c
@@ -343,7 +343,10 @@ static VALUE dir_close(VALUE);
/* 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)
diff --git a/file.c b/file.c
index b872002c2f9..ef7ad0e777a 100644
--- a/file.c
+++ b/file.c
@@ -127,6 +127,7 @@ rb_get_path_check(VALUE obj, int level)
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);
}
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 0ea28f55d8c..eb315d3d85b 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -161,6 +161,11 @@ class TestDir < Test::Unit::TestCase
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
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 881edb57acc..e7d60960b83 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -3,6 +3,13 @@ require "fileutils"
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 @@ class TestFileExhaustive < Test::Unit::TestCase
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 @@ class TestFileExhaustive < Test::Unit::TestCase
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 @@ class TestFileExhaustive < Test::Unit::TestCase
end
end
end
+
+ assert_incompatible_encoding {|d| File.extname(d)}
end
def test_split