summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--file.c6
-rw-r--r--test/ruby/test_file_exhaustive.rb2
3 files changed, 12 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b78f7d2c05..40b285e9eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Mar 13 00:44:20 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (rb_file_s_basename): check encoding of suffix.
+
Sat Mar 13 00:11:05 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (ruby_init_loadpath_safe): mark initial load paths.
diff --git a/file.c b/file.c
index 50516ad4f8..4e0a0f13e4 100644
--- a/file.c
+++ b/file.c
@@ -3324,9 +3324,15 @@ rb_file_s_basename(int argc, VALUE *argv)
long f, n;
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
+ rb_encoding *enc;
StringValue(fext);
+ if (!rb_enc_asciicompat(enc = rb_enc_get(fext))) {
+ rb_raise(rb_eEncCompatError, "ascii incompatible character encodings: %s",
+ rb_enc_name(enc));
+ }
}
FilePathStringValue(fname);
+ if (!NIL_P(fext)) rb_enc_check(fname, fext);
if (RSTRING_LEN(fname) == 0 || !*(name = RSTRING_PTR(fname)))
return rb_str_new_shared(fname);
name = skipprefix(name);
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 74b960c54f..4a26e435b8 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -423,6 +423,8 @@ class TestFileExhaustive < Test::Unit::TestCase
end
assert_incompatible_encoding {|d| File.basename(d)}
+ assert_incompatible_encoding {|d| File.basename(d, ".*")}
+ assert_raise(Encoding::CompatibilityError) {File.basename("foo.ext", ".*".encode("utf-16le"))}
end
def test_dirname