From 61aff0cd189e67fa6f2565639ad0128fa33b88fc Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku 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] --- file.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index c46377b933..170455ab0a 100644 --- a/file.c +++ b/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" -- cgit v1.2.3