зеркало из https://github.com/github/ruby.git
* file.c (rb_file_s_extname): first dot is not an extension name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c39e8c6e85
Коммит
34c96140f3
|
@ -1,3 +1,7 @@
|
|||
Sat May 17 11:29:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* file.c (rb_file_s_extname): first dot is not an extension name.
|
||||
|
||||
Sat May 17 03:21:29 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_sort_bang): stop memory leak. [ruby-dev:34726]
|
||||
|
|
4
file.c
4
file.c
|
@ -3104,7 +3104,7 @@ rb_file_s_extname(VALUE klass, VALUE fname)
|
|||
if (!p)
|
||||
p = name;
|
||||
else
|
||||
p++;
|
||||
name = ++p;
|
||||
|
||||
e = 0;
|
||||
while (*p) {
|
||||
|
@ -3134,7 +3134,7 @@ rb_file_s_extname(VALUE klass, VALUE fname)
|
|||
break;
|
||||
p = CharNext(p);
|
||||
}
|
||||
if (!e || e+1 == p) /* no dot, or the only dot is first or end? */
|
||||
if (!e || e == name || e+1 == p) /* no dot, or the only dot is first or end? */
|
||||
return rb_str_new(0, 0);
|
||||
extname = rb_str_new(e, p - e); /* keep the dot, too! */
|
||||
rb_enc_copy(extname, fname);
|
||||
|
|
|
@ -411,6 +411,17 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_extname
|
||||
assert(".test", File.extname(@file))
|
||||
assert_equal("", File.extname("foo"))
|
||||
assert_equal("", File.extname("/foo"))
|
||||
assert_equal("", File.extname(".foo"))
|
||||
assert_equal("", File.extname("/.foo"))
|
||||
assert_equal("", File.extname("bar/.foo"))
|
||||
assert_equal("", File.extname("/bar/.foo"))
|
||||
assert_equal(".ext", File.extname("foo.ext"))
|
||||
assert_equal(".ext", File.extname("/foo.ext"))
|
||||
assert_equal(".ext", File.extname(".foo.ext"))
|
||||
assert_equal(".ext", File.extname("/.foo.ext"))
|
||||
assert_equal(".ext", File.extname("bar/.foo.ext"))
|
||||
assert_equal(".ext", File.extname("/bar/.foo.ext"))
|
||||
assert_equal("", File.extname(""))
|
||||
if /cygwin|mingw|mswin|bccwin/ =~ RUBY_PLATFORM
|
||||
assert_equal("", File.extname("foo "))
|
||||
|
|
Загрузка…
Ссылка в новой задаче