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
|
* compress_path
|
||||||
*
|
*
|
||||||
* This assumes sizeof(char) == 1 which is probably a really bad idea.
|
* This assumes sizeof(char) == 1 which is probably a really bad idea.
|
||||||
|
* ^ actually that's guaranteed by C standard -nortti, 2021
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
compress_path(mp, c, cwd)
|
compress_path(mp, c, cwd)
|
||||||
|
@ -78,7 +79,10 @@ char *cwd;
|
||||||
if (*cwd != '/') return(NULL);
|
if (*cwd != '/') return(NULL);
|
||||||
r = (char *)MPGet(mp, strlen("/") + strlen(c) + strlen(cwd) + 1);
|
r = (char *)MPGet(mp, strlen("/") + strlen(c) + strlen(cwd) + 1);
|
||||||
strcpy(r, cwd);
|
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);
|
strcat(r, c);
|
||||||
}
|
}
|
||||||
else r = MPStrDup(mp, c);
|
else r = MPStrDup(mp, c);
|
||||||
|
@ -88,12 +92,7 @@ char *cwd;
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
{
|
{
|
||||||
p1 = p + 1;
|
p1 = p + 1;
|
||||||
if (*p1 == '/')
|
if (*p1 == '.')
|
||||||
{
|
|
||||||
memmove(p, p1, strlen(p1) + 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (*p1 == '.')
|
|
||||||
{
|
{
|
||||||
p2 = p1 + 1;
|
p2 = p1 + 1;
|
||||||
if (*p2 == '/')
|
if (*p2 == '/')
|
||||||
|
|
Loading…
Reference in New Issue