summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-16 13:42:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-16 13:42:17 +0000
commita2bb19fa9fc0e4b32fb53049d2611cf19618d847 (patch)
tree2a0ca02638563200915743fff9b37eae6b915927 /file.c
parent86310f3e894cec7f7c3e26c29bf9c2365828f65b (diff)
* file.c (rb_file_s_extname): empty string for path name ending with a
period. fixed: [ruby-core:05651] * file.c (rb_file_join): smarter behavior at edge cases. fixed: [ruby-core:05706] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/file.c b/file.c
index fce522d..818d808 100644
--- a/file.c
+++ b/file.c
@@ -2675,7 +2675,7 @@ rb_file_s_extname(klass, fname)
p++;
e = strrchr(p, '.'); /* get the last dot of the last component */
- if (!e || e == p) /* no dot, or the only dot is first? */
+ if (!e || e == p || !e[1]) /* no dot, or the only dot is first or end? */
return rb_str_new2("");
extname = rb_str_new(e, chompdirsep(e) - e); /* keep the dot, too! */
OBJ_INFECT(extname, fname);
@@ -2720,7 +2720,7 @@ rb_file_join(ary, sep)
long len, i;
int taint = 0;
VALUE result, tmp;
- char *name;
+ char *name, *tail;
if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
if (OBJ_TAINTED(ary)) taint = 1;
@@ -2757,11 +2757,18 @@ rb_file_join(ary, sep)
}
break;
default:
- tmp = rb_obj_as_string(tmp);
+ StringValueCStr(tmp);
}
name = StringValueCStr(result);
- if (i > 0 && !NIL_P(sep) && !*chompdirsep(name))
- rb_str_buf_append(result, sep);
+ if (i > 0 && !NIL_P(sep)) {
+ tail = chompdirsep(name);
+ if (isdirsep(RSTRING(tmp)->ptr[0])) {
+ RSTRING(result)->len = tail - name;
+ }
+ else if (!*tail) {
+ rb_str_buf_append(result, sep);
+ }
+ }
rb_str_buf_append(result, tmp);
if (OBJ_TAINTED(tmp)) taint = 1;
}