[前][次][番号順一覧][スレッド一覧]

ruby-changes:59359

From: NAKAMURA <ko1@a...>
Date: Sun, 22 Dec 2019 02:42:40 +0900 (JST)
Subject: [ruby-changes:59359] 61aff0cd18 (master): Should return "." for File.extname("file.") also on Windows

https://git.ruby-lang.org/ruby.git/commit/?id=61aff0cd18

From 61aff0cd189e67fa6f2565639ad0128fa33b88fc Mon Sep 17 00:00:00 2001
From: NAKAMURA Usaku <usa@r...>
Date: Sun, 22 Dec 2019 02:36:55 +0900
Subject: Should return "." for File.extname("file.") also on Windows

But not changes another cases, such as "file.rb."
[Bug #15267]

diff --git a/file.c b/file.c
index c46377b..170455a 100644
--- a/file.c
+++ b/file.c
@@ -4711,13 +4711,26 @@ ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/file.c#L4711
     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) https://github.com/ruby/ruby/blob/trunk/file.c#L4779
  *     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"
diff --git a/spec/ruby/core/file/extname_spec.rb b/spec/ruby/core/file/extname_spec.rb
index e9b53bc..7929096 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/extname_spec.rb#L23
   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 == "."
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 975bcb6..de4c21e 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -1268,19 +1268,19 @@ class TestFileExhaustive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L1268
     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
diff --git a/test/ruby/test_path.rb b/test/ruby/test_path.rb
index b35e942..64111ee 100644
--- a/test/ruby/test_path.rb
+++ b/test/ruby/test_path.rb
@@ -239,11 +239,7 @@ class TestPath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_path.rb#L239
       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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]