1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* file.c (file_expand_path): fix surplus path separators while

expanding at root directory.  [ruby-dev:19572]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-02-14 16:09:07 +00:00
parent bfa0275833
commit f2d07eb82d
3 changed files with 40 additions and 17 deletions

View file

@ -1,3 +1,8 @@
Sat Feb 15 01:01:45 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* file.c (file_expand_path): fix surplus path separators while
expanding at root directory. [ruby-dev:19572]
Fri Feb 14 14:25:24 2003 akira yamada <akira@arika.org> Fri Feb 14 14:25:24 2003 akira yamada <akira@arika.org>
* lib/uri/generic.rb, lib/uri/ldap.rb, lib/uri/mailto.ldap: all foo=() * lib/uri/generic.rb, lib/uri/ldap.rb, lib/uri/mailto.ldap: all foo=()

37
file.c
View file

@ -1577,6 +1577,17 @@ file_expand_path(fname, dname, result)
tainted = 1; tainted = 1;
getcwd(buf, MAXPATHLEN); getcwd(buf, MAXPATHLEN);
p = &buf[2]; p = &buf[2];
if (!isdirsep(*p)) {
while (*p && !isdirsep(*p)) {
p = CharNext(p);
}
if (*p) {
p++;
while (*p && !isdirsep(*p)) {
p = CharNext(p);
}
}
}
b = s; b = s;
while (*s && !isdirsep(*s)) { while (*s && !isdirsep(*s)) {
s = CharNext(s); s = CharNext(s);
@ -1598,15 +1609,18 @@ file_expand_path(fname, dname, result)
strcpy(buf, dir); strcpy(buf, dir);
free(dir); free(dir);
} }
p = chompdirsep(skiproot(buf)); p = skiproot(buf);
if (*p)
p = chompdirsep(p);
else
--p;
} }
else { else {
while (*s && isdirsep(*s)) { b = s;
*p++ = '/'; do s++; while (isdirsep(*s));
p = buf + (s - b) - 1;
BUFCHECK(p >= pend); BUFCHECK(p >= pend);
s++; memset(buf, '/', p - buf);
}
if (p > buf && *s) p--;
} }
*p = '/'; *p = '/';
@ -1667,16 +1681,7 @@ file_expand_path(fname, dname, result)
memcpy(++p, b, s-b); memcpy(++p, b, s-b);
p += s-b; p += s-b;
} }
#ifdef DOSISH_DRIVE_LETTER if (p == skiproot(buf) - 1) p++;
else if (ISALPHA(buf[0]) && (buf[1] == ':') && isdirsep(buf[2])) {
/* root directory needs a trailing backslash,
otherwise it mean the current directory of the drive */
if (p == (buf+2)) p++;
}
else if (isdirsep(buf[0]) && isdirsep(buf[1])) {
if (p == (buf+1)) p++;
}
#endif
if (tainted) OBJ_TAINT(result); if (tainted) OBJ_TAINT(result);
RSTRING(result)->len = p - buf; RSTRING(result)->len = p - buf;

View file

@ -1671,6 +1671,19 @@ test_ok(File.dirname("a/b/c") == "a/b")
test_ok(File.dirname("/a/b/c") == "/a/b") test_ok(File.dirname("/a/b/c") == "/a/b")
test_ok(File.dirname("/a/b/") == "/a") test_ok(File.dirname("/a/b/") == "/a")
test_ok(File.dirname("/a/b///") == "/a") test_ok(File.dirname("/a/b///") == "/a")
case Dir.pwd
when %r'\A\w:'
test_ok(/\A\w:\/\z/ =~ File.expand_path(".", "/"))
test_ok(/\A\w:\/a\z/ =~ File.expand_path("a", "/"))
when %r'\A//'
test_ok(%r'\A//[^/]+/[^/]+\z' =~ File.expand_path(".", "/"))
test_ok(%r'\A//[^/]+/[^/]+/a\z' =~ File.expand_path(".", "/"))
else
test_ok(File.expand_path(".", "/") == "/")
test_ok(File.expand_path("sub", "/") == "/sub")
end
test_ok(File.expand_path(".", "//") == "//")
test_ok(File.expand_path("sub", "//") == "//sub")
test_check "gc" test_check "gc"
begin begin