mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* file.c (rb_file_s_basename): ignore non-ascii extension in
different encoding, which cannot match. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b094ab0948
commit
97f0b0f558
3 changed files with 11 additions and 8 deletions
|
@ -1,4 +1,7 @@
|
|||
Wed Jan 25 11:40:26 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Wed Jan 25 13:27:42 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* file.c (rb_file_s_basename): ignore non-ascii extension in
|
||||
different encoding, which cannot match.
|
||||
|
||||
* file.c (rmext): no extension to strip if empty string.
|
||||
|
||||
|
|
11
file.c
11
file.c
|
@ -3658,8 +3658,10 @@ rb_file_s_basename(int argc, VALUE *argv)
|
|||
}
|
||||
}
|
||||
FilePathStringValue(fname);
|
||||
if (!NIL_P(fext)) enc = rb_enc_check(fname, fext);
|
||||
else enc = rb_enc_get(fname);
|
||||
if (NIL_P(fext) || !(enc = rb_enc_compatible(fname, fext))) {
|
||||
enc = rb_enc_get(fname);
|
||||
fext = Qnil;
|
||||
}
|
||||
if ((n = RSTRING_LEN(fname)) == 0 || !*(name = RSTRING_PTR(fname)))
|
||||
return rb_str_new_shared(fname);
|
||||
|
||||
|
@ -3669,12 +3671,7 @@ rb_file_s_basename(int argc, VALUE *argv)
|
|||
f = n;
|
||||
}
|
||||
else {
|
||||
rb_encoding *fenc = rb_enc_get(fext);
|
||||
const char *fp;
|
||||
if (enc != fenc &&
|
||||
rb_enc_str_coderange(fext) != ENC_CODERANGE_7BIT) {
|
||||
fext = rb_str_conv_enc(fext, fenc, enc);
|
||||
}
|
||||
fp = StringValueCStr(fext);
|
||||
if (!(f = rmext(p, f, n, fp, RSTRING_LEN(fext), enc))) {
|
||||
f = n;
|
||||
|
|
|
@ -478,6 +478,9 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
s = "foo\x93_a".force_encoding("cp932")
|
||||
assert_equal(s, File.basename(s, "_a"))
|
||||
|
||||
s = "\u4032.\u3024"
|
||||
assert_equal(s, File.basename(s, ".\x95\\".force_encoding("cp932")))
|
||||
end
|
||||
|
||||
def test_dirname
|
||||
|
|
Loading…
Add table
Reference in a new issue