mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* file.c (rb_file_s_basename): check encoding of suffix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fbdabf398f
commit
0884036a0a
3 changed files with 12 additions and 0 deletions
|
@ -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.
|
||||
|
|
6
file.c
6
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue