]> sjero.net Git - wget/commitdiff
[svn] Don't preserve ".." at beginning of path.
authorhniksic <devnull@localhost>
Tue, 28 Feb 2006 17:41:09 +0000 (09:41 -0800)
committerhniksic <devnull@localhost>
Tue, 28 Feb 2006 17:41:09 +0000 (09:41 -0800)
src/ChangeLog
src/url.c

index 6a98096831e6c9c6ee03c1f56b80e0d6b7178fa3..46a550feb94cc834cdde767369f91389e84905aa 100644 (file)
@@ -1,3 +1,8 @@
+2006-02-27  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * url.c (path_simplify): Don't preserve ".." at beginning of path.
+       Suggested by Frank McCown.
+
 2006-02-25  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * http.c (gethttp): Only use FILE.N.html if FILE.html exists.
 2006-02-25  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * http.c (gethttp): Only use FILE.N.html if FILE.html exists.
index a4d7bdb10b4de4b6c31e565031eaf19283c51aef..f97a31801ea5a6861fccc47b4a1d4d60632bf6b0 100644 (file)
--- 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 *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)
     {
 
   while (h < end)
     {
@@ -1527,26 +1526,17 @@ path_simplify (char *path)
        {
          /* Handle "../" by retreating the tortoise by one path
             element -- but not past beggining.  */
        {
          /* 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. */
            {
              /* 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
        {
          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.  */
          /* 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 },
     { ".",                     "",             true },
     { "./",                    "",             true },
-    { "..",                    "..",           false },
-    { "../",                   "../",          false },
+    { "..",                    "",             true },
+    { "../",                   "",             true },
     { "foo",                   "foo",          false },
     { "foo/bar",               "foo/bar",      false },
     { "foo///bar",             "foo///bar",    false },
     { "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/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 }
   };
     { "a/b/../../c",           "c",            true },
     { "./a/../b",              "b",            true }
   };