Fix some path compression bugs.

This commit is contained in:
Bill Currie 2010-08-25 12:04:58 +09:00
parent 550b094b93
commit f1943ebaab
2 changed files with 13 additions and 1 deletions

View file

@ -785,7 +785,14 @@ QFS_CompressPath (const char *pth)
d--; d--;
if (d == path if (d == path
&& d[0] == '.' && d[1] == '.' && d[0] == '.' && d[1] == '.'
&& (d[2] == '/' || d[2] == '0')) { && (d[2] == '/' || d[2] == '\0')) {
p += 2 + (p[2] == '/');
continue;
}
if (d[0] == '/'
&& d[1] == '.' && d[2] == '.'
&& (d[3] == '/' || d[3] == '\0')) {
*p = 0;
p += 2 + (p[2] == '/'); p += 2 + (p[2] == '/');
continue; continue;
} }
@ -804,12 +811,16 @@ QFS_CompressPath (const char *pth)
p++; p++;
if (*p == '/') { if (*p == '/') {
p++; p++;
// skip over multiple / (foo//bar -> foo/bar)
for (d = p; *d == '/'; d++) for (d = p; *d == '/'; d++)
; ;
if (d != p) if (d != p)
strcpy (p, d); strcpy (p, d);
} }
} }
// strip any trailing /, but not if it's the root /
if (--p != path && *p == '/')
*p = 0;
return path; return path;
} }

View file

@ -24,6 +24,7 @@ struct {
{"/..", "/"}, {"/..", "/"},
{"foo/..", ""}, {"foo/..", ""},
{"foo/bar/..", "foo"}, {"foo/bar/..", "foo"},
{"foo//bar", "foo/bar"},
{"../foo/..", ".."}, {"../foo/..", ".."},
{"\\blah\\../foo/..\\baz/.\\x", "/baz/x"}, {"\\blah\\../foo/..\\baz/.\\x", "/baz/x"},
}; };