mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Should return "." for File.extname("file.") also on Windows
But not changes another cases, such as "file.rb." [Bug #15267]
This commit is contained in:
parent
29ea228efc
commit
61aff0cd18
4 changed files with 23 additions and 15 deletions
22
file.c
22
file.c
|
@ -4711,13 +4711,26 @@ ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
|
|||
while (*p) {
|
||||
if (*p == '.' || istrailinggarbage(*p)) {
|
||||
#if USE_NTFS
|
||||
const char *last = p++, *dot = last;
|
||||
const char *first = 0, *last, *dot;
|
||||
if (*p == '.') first = p;
|
||||
last = p++;
|
||||
dot = last;
|
||||
while (istrailinggarbage(*p)) {
|
||||
if (*p == '.') dot = p;
|
||||
if (*p == '.') {
|
||||
dot = p;
|
||||
if (!first) {
|
||||
first = p;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (!*p || isADS(*p)) {
|
||||
p = last;
|
||||
if (first == dot && e == 0) {
|
||||
e = first;
|
||||
}
|
||||
else {
|
||||
p = last;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (*last == '.' || dot > last) e = dot;
|
||||
|
@ -4766,8 +4779,7 @@ ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
|
|||
* File.extname("test.rb") #=> ".rb"
|
||||
* File.extname("a/b/d/test.rb") #=> ".rb"
|
||||
* File.extname(".a/b/d/test.rb") #=> ".rb"
|
||||
* File.extname("foo.") #=> "" on Windows
|
||||
* File.extname("foo.") #=> "." on non-Windows
|
||||
* File.extname("foo.") #=> "."
|
||||
* File.extname("test") #=> ""
|
||||
* File.extname(".profile") #=> ""
|
||||
* File.extname(".profile.sh") #=> ".sh"
|
||||
|
|
|
@ -23,14 +23,14 @@ describe "File.extname" do
|
|||
end
|
||||
|
||||
describe "for a filename ending with a dot" do
|
||||
guard -> { platform_is :windows or ruby_version_is ""..."2.7" } do
|
||||
ruby_version_is ""..."2.7" do
|
||||
it "returns ''" do
|
||||
File.extname(".foo.").should == ""
|
||||
File.extname("foo.").should == ""
|
||||
end
|
||||
end
|
||||
|
||||
guard -> { platform_is_not :windows and ruby_version_is "2.7" } do
|
||||
ruby_version_is "2.7" do
|
||||
it "returns '.'" do
|
||||
File.extname(".foo.").should == "."
|
||||
File.extname("foo.").should == "."
|
||||
|
|
|
@ -1268,19 +1268,19 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
infixes2 = infixes + [".ext "]
|
||||
appendixes = [""]
|
||||
if NTFS
|
||||
appendixes << " " << "." << "::$DATA" << "::$DATA.bar"
|
||||
appendixes << " " << [".", ".", ""] << "::$DATA" << "::$DATA.bar"
|
||||
else
|
||||
appendixes << [".", "."]
|
||||
end
|
||||
prefixes.each do |prefix|
|
||||
appendixes.each do |appendix, ext = ""|
|
||||
appendixes.each do |appendix, ext = "", ext2 = ext|
|
||||
infixes.each do |infix|
|
||||
path = "#{prefix}foo#{infix}#{appendix}"
|
||||
assert_equal(ext, File.extname(path), "File.extname(#{path.inspect})")
|
||||
end
|
||||
infixes2.each do |infix|
|
||||
path = "#{prefix}foo#{infix}.ext#{appendix}"
|
||||
assert_equal(ext.empty? ? ".ext" : appendix, File.extname(path), "File.extname(#{path.inspect})")
|
||||
assert_equal(ext2.empty? ? ".ext" : appendix, File.extname(path), "File.extname(#{path.inspect})")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -239,11 +239,7 @@ class TestPath < Test::Unit::TestCase
|
|||
ext = '.'
|
||||
end
|
||||
assert_equal(ext, File.extname('a.rb.'))
|
||||
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
|
||||
# trailing spaces and dots are ignored on NTFS.
|
||||
ext = ''
|
||||
end
|
||||
assert_equal(ext, File.extname('a.'))
|
||||
assert_equal('.', File.extname('a.'))
|
||||
assert_equal('', File.extname('.x'))
|
||||
assert_equal('', File.extname('..x'))
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue