From: hniksic Date: Tue, 28 Feb 2006 17:41:09 +0000 (-0800) Subject: [svn] Don't preserve ".." at beginning of path. X-Git-Tag: v1.13~679 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=aa07e689f2c03dd25342859e7e527a13467ad219 [svn] Don't preserve ".." at beginning of path. --- diff --git a/src/ChangeLog b/src/ChangeLog index 6a980968..46a550fe 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2006-02-27 Hrvoje Niksic + + * url.c (path_simplify): Don't preserve ".." at beginning of path. + Suggested by Frank McCown. + 2006-02-25 Hrvoje Niksic * http.c (gethttp): Only use FILE.N.html if FILE.html exists. diff --git a/src/url.c b/src/url.c index a4d7bdb1..f97a3180 100644 --- a/src/url.c +++ b/src/url.c @@ -1511,8 +1511,7 @@ path_simplify (char *path) { char *h = path; /* hare */ char *t = path; /* tortoise */ - char *beg = path; /* boundary for backing the tortoise */ - char *end = path + strlen (path); + char *end = strchr (path, '\0'); while (h < end) { @@ -1527,26 +1526,17 @@ path_simplify (char *path) { /* Handle "../" by retreating the tortoise by one path element -- but not past beggining. */ - if (t > beg) + if (t > path) { /* Move backwards until T hits the beginning of the previous path element or the beginning of path. */ - for (--t; t > beg && t[-1] != '/'; t--) + for (--t; t > path && t[-1] != '/'; t--) ; } - else - { - /* If we're at the beginning, copy the "../" literally - move the beginning so a later ".." doesn't remove - it. */ - beg = t + 3; - goto regular; - } h += 3; } else { - regular: /* A regular path element. If H hasn't advanced past T, simply skip to the next path element. Otherwise, copy the path element until the next slash. */ @@ -1972,8 +1962,8 @@ test_path_simplify (void) { "", "", false }, { ".", "", true }, { "./", "", true }, - { "..", "..", false }, - { "../", "../", false }, + { "..", "", true }, + { "../", "", true }, { "foo", "foo", false }, { "foo/bar", "foo/bar", false }, { "foo///bar", "foo///bar", false }, @@ -1986,9 +1976,9 @@ test_path_simplify (void) { "foo/bar/../x", "foo/x", true }, { "foo/bar/../x/", "foo/x/", true }, { "foo/..", "", true }, - { "foo/../..", "..", true }, - { "foo/../../..", "../..", true }, - { "foo/../../bar/../../baz", "../../baz", true }, + { "foo/../..", "", true }, + { "foo/../../..", "", true }, + { "foo/../../bar/../../baz", "baz", true }, { "a/b/../../c", "c", true }, { "./a/../b", "b", true } };