X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Furl.c;h=f97a31801ea5a6861fccc47b4a1d4d60632bf6b0;hp=a4d7bdb10b4de4b6c31e565031eaf19283c51aef;hb=aa07e689f2c03dd25342859e7e527a13467ad219;hpb=e8b61e46abd8471f0ea45a827a53b0eb5b3220cc 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 } };