mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-10 12:55:48 +01:00
Canonicalize paths that start with more than two slashes.
2008-01-22 Alexander Larsson <alexl@redhat.com> * glocalfile.c: (canonicalize_filename): Canonicalize paths that start with more than two slashes. * tests/g-file.c: (compare_two_files): (test_g_file_new_for_path): Test the above svn path=/trunk/; revision=6353
This commit is contained in:
parent
db5224fa85
commit
2544ae3cd6
@ -1,3 +1,15 @@
|
|||||||
|
2008-01-22 Alexander Larsson <alexl@redhat.com>
|
||||||
|
|
||||||
|
* glocalfile.c:
|
||||||
|
(canonicalize_filename):
|
||||||
|
Canonicalize paths that start with more than
|
||||||
|
two slashes.
|
||||||
|
|
||||||
|
* tests/g-file.c:
|
||||||
|
(compare_two_files):
|
||||||
|
(test_g_file_new_for_path):
|
||||||
|
Test the above
|
||||||
|
|
||||||
2008-01-22 Alexander Larsson <alexl@redhat.com>
|
2008-01-22 Alexander Larsson <alexl@redhat.com>
|
||||||
|
|
||||||
* glocalfile.c:
|
* glocalfile.c:
|
||||||
|
@ -214,6 +214,7 @@ canonicalize_filename (const char *filename)
|
|||||||
{
|
{
|
||||||
char *canon, *start, *p, *q;
|
char *canon, *start, *p, *q;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!g_path_is_absolute (filename))
|
if (!g_path_is_absolute (filename))
|
||||||
{
|
{
|
||||||
@ -226,6 +227,24 @@ canonicalize_filename (const char *filename)
|
|||||||
|
|
||||||
start = (char *)g_path_skip_root (canon);
|
start = (char *)g_path_skip_root (canon);
|
||||||
|
|
||||||
|
/* POSIX allows double slashes at the start to
|
||||||
|
* mean something special (as does windows too).
|
||||||
|
* So, "//" != "/", but more than two slashes
|
||||||
|
* is treated as "/".
|
||||||
|
*/
|
||||||
|
i = 0;
|
||||||
|
for (p = start - 1;
|
||||||
|
(p >= canon) &&
|
||||||
|
G_IS_DIR_SEPARATOR (*p);
|
||||||
|
p--)
|
||||||
|
i++;
|
||||||
|
if (i > 2)
|
||||||
|
{
|
||||||
|
i -= 1;
|
||||||
|
start -= i;
|
||||||
|
memmove (start, start+i, strlen (start+i)+1);
|
||||||
|
}
|
||||||
|
|
||||||
p = start;
|
p = start;
|
||||||
while (*p != 0)
|
while (*p != 0)
|
||||||
{
|
{
|
||||||
|
@ -120,7 +120,8 @@ test_g_file_new_for_path (void)
|
|||||||
{"/", TRUE, 0, "/somedir/../"},
|
{"/", TRUE, 0, "/somedir/../"},
|
||||||
{"/", FALSE, 0, "/somedir/.../"},
|
{"/", FALSE, 0, "/somedir/.../"},
|
||||||
{"//tmp/dir1", TRUE, 0, "//tmp/dir1"},
|
{"//tmp/dir1", TRUE, 0, "//tmp/dir1"},
|
||||||
/* Should not fail: {"/tmp/dir1", TRUE, 0, "///tmp/dir1"}, */
|
{"/tmp/dir1", TRUE, 0, "///tmp/dir1"},
|
||||||
|
{"/tmp/dir1", TRUE, 0, "////tmp/dir1"},
|
||||||
{"/tmp/dir1", TRUE, 0, "/tmp/./dir1"},
|
{"/tmp/dir1", TRUE, 0, "/tmp/./dir1"},
|
||||||
{"/tmp/dir1", TRUE, 0, "/tmp//dir1"},
|
{"/tmp/dir1", TRUE, 0, "/tmp//dir1"},
|
||||||
{"/tmp/dir1", TRUE, 0, "/tmp///dir1///"},
|
{"/tmp/dir1", TRUE, 0, "/tmp///dir1///"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user