summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.c22
-rw-r--r--spec/ruby/core/file/extname_spec.rb4
-rw-r--r--test/ruby/test_file_exhaustive.rb6
-rw-r--r--test/ruby/test_path.rb6
4 files changed, 15 insertions, 23 deletions
diff --git a/file.c b/file.c
index 170455ab0ae..c46377b9332 100644
--- a/file.c
+++ b/file.c
@@ -4711,26 +4711,13 @@ ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
while (*p) {
if (*p == '.' || istrailinggarbage(*p)) {
#if USE_NTFS
- const char *first = 0, *last, *dot;
- if (*p == '.') first = p;
- last = p++;
- dot = last;
+ const char *last = p++, *dot = last;
while (istrailinggarbage(*p)) {
- if (*p == '.') {
- dot = p;
- if (!first) {
- first = p;
- }
- }
+ if (*p == '.') dot = p;
p++;
}
if (!*p || isADS(*p)) {
- if (first == dot && e == 0) {
- e = first;
- }
- else {
- p = last;
- }
+ p = last;
break;
}
if (*last == '.' || dot > last) e = dot;
@@ -4779,7 +4766,8 @@ 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.") #=> "."
+ * File.extname("foo.") #=> "" on Windows
+ * File.extname("foo.") #=> "." on non-Windows
* File.extname("test") #=> ""
* File.extname(".profile") #=> ""
* File.extname(".profile.sh") #=> ".sh"
diff --git a/spec/ruby/core/file/extname_spec.rb b/spec/ruby/core/file/extname_spec.rb
index 79290960fbd..e9b53bc24d0 100644
--- a/spec/ruby/core/file/extname_spec.rb
+++ b/spec/ruby/core/file/extname_spec.rb
@@ -23,14 +23,14 @@ describe "File.extname" do
end
describe "for a filename ending with a dot" do
- ruby_version_is ""..."2.7" do
+ guard -> { platform_is :windows or ruby_version_is ""..."2.7" } do
it "returns ''" do
File.extname(".foo.").should == ""
File.extname("foo.").should == ""
end
end
- ruby_version_is "2.7" do
+ guard -> { platform_is_not :windows and ruby_version_is "2.7" } do
it "returns '.'" do
File.extname(".foo.").should == "."
File.extname("foo.").should == "."
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index de4c21e5ca3..975bcb6bc2d 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -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 = "", ext2 = ext|
+ appendixes.each do |appendix, 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(ext2.empty? ? ".ext" : appendix, File.extname(path), "File.extname(#{path.inspect})")
+ assert_equal(ext.empty? ? ".ext" : appendix, File.extname(path), "File.extname(#{path.inspect})")
end
end
end
diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb
index 64111ee8057..b35e942a2a0 100644
--- a/test/ruby/test_path.rb
+++ b/test/ruby/test_path.rb
@@ -239,7 +239,11 @@ class TestPath < Test::Unit::TestCase
ext = '.'
end
assert_equal(ext, File.extname('a.rb.'))
- assert_equal('.', File.extname('a.'))
+ 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('.x'))
assert_equal('', File.extname('..x'))
end