Don't collapse // → / in compress_path(), and avoid generating // in the first place
This commit is contained in:
parent
eb9111646e
commit
70e751e46a
13
common/dir.c
13
common/dir.c
|
@ -62,6 +62,7 @@ char *p;
|
|||
* compress_path
|
||||
*
|
||||
* This assumes sizeof(char) == 1 which is probably a really bad idea.
|
||||
* ^ actually that's guaranteed by C standard -nortti, 2021
|
||||
*/
|
||||
char *
|
||||
compress_path(mp, c, cwd)
|
||||
|
@ -78,7 +79,10 @@ char *cwd;
|
|||
if (*cwd != '/') return(NULL);
|
||||
r = (char *)MPGet(mp, strlen("/") + strlen(c) + strlen(cwd) + 1);
|
||||
strcpy(r, cwd);
|
||||
strcat(r, "/");
|
||||
// Only add the slash if we don't already have one
|
||||
// That is, if cwd ends in a slash, don't add an extra one
|
||||
if (r[strlen(cwd) - 1] != '/')
|
||||
strcat(r, "/");
|
||||
strcat(r, c);
|
||||
}
|
||||
else r = MPStrDup(mp, c);
|
||||
|
@ -88,12 +92,7 @@ char *cwd;
|
|||
if (*p == '/')
|
||||
{
|
||||
p1 = p + 1;
|
||||
if (*p1 == '/')
|
||||
{
|
||||
memmove(p, p1, strlen(p1) + 1);
|
||||
continue;
|
||||
}
|
||||
else if (*p1 == '.')
|
||||
if (*p1 == '.')
|
||||
{
|
||||
p2 = p1 + 1;
|
||||
if (*p2 == '/')
|
||||
|
|
Loading…
Reference in New Issue