summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorNAKAMURA Usaku <usa@ruby-lang.org>2019-12-22 02:36:55 +0900
committerNAKAMURA Usaku <usa@ruby-lang.org>2019-12-22 02:42:09 +0900
commit61aff0cd189e67fa6f2565639ad0128fa33b88fc (patch)
treec1aaf72ca72f4f0e0f98655aef940299b1091ddc /file.c
parent29ea228efc5af08a0e91fafe155617f20e22976b (diff)
Should return "." for File.extname("file.") also on Windows
But not changes another cases, such as "file.rb." [Bug #15267]
Diffstat (limited to 'file.c')
-rw-r--r--file.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/file.c b/file.c
index c46377b9332..170455ab0ae 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"