* 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
@ -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.
|
* 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);
|
FilePathStringValue(fname);
|
||||||
if (!NIL_P(fext)) enc = rb_enc_check(fname, fext);
|
if (NIL_P(fext) || !(enc = rb_enc_compatible(fname, fext))) {
|
||||||
else enc = rb_enc_get(fname);
|
enc = rb_enc_get(fname);
|
||||||
|
fext = Qnil;
|
||||||
|
}
|
||||||
if ((n = RSTRING_LEN(fname)) == 0 || !*(name = RSTRING_PTR(fname)))
|
if ((n = RSTRING_LEN(fname)) == 0 || !*(name = RSTRING_PTR(fname)))
|
||||||
return rb_str_new_shared(fname);
|
return rb_str_new_shared(fname);
|
||||||
|
|
||||||
@ -3669,12 +3671,7 @@ rb_file_s_basename(int argc, VALUE *argv)
|
|||||||
f = n;
|
f = n;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_encoding *fenc = rb_enc_get(fext);
|
|
||||||
const char *fp;
|
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);
|
fp = StringValueCStr(fext);
|
||||||
if (!(f = rmext(p, f, n, fp, RSTRING_LEN(fext), enc))) {
|
if (!(f = rmext(p, f, n, fp, RSTRING_LEN(fext), enc))) {
|
||||||
f = n;
|
f = n;
|
||||||
|
@ -478,6 +478,9 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||||||
|
|
||||||
s = "foo\x93_a".force_encoding("cp932")
|
s = "foo\x93_a".force_encoding("cp932")
|
||||||
assert_equal(s, File.basename(s, "_a"))
|
assert_equal(s, File.basename(s, "_a"))
|
||||||
|
|
||||||
|
s = "\u4032.\u3024"
|
||||||
|
assert_equal(s, File.basename(s, ".\x95\\".force_encoding("cp932")))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dirname
|
def test_dirname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user