Vladimir Volovich <[EMAIL PROTECTED]> writes:

> this is not strictly speaking a bug, but is an inconsistency.
> 
> when i run
> 
> wget -x http://some.host/path%20to%20file/file%20name.html
> 
> wget saves the result in "some.host/path%20to%20file/file name.html"
> 
> i.e. it decodes %-characters in filename, but not in directory
> name(s).

The inconsistency is a bug.  It is intended that Wget encodes all the
unsafe characters, both in files and directories.  (It is debatable
whether that is a bug.)  This patch makes it consistent, but I will
not apply it before the 1.8.1 release:

Index: src/url.c
===================================================================
RCS file: /pack/anoncvs/wget/src/url.c,v
retrieving revision 1.67
diff -u -r1.67 url.c
--- src/url.c   2001/12/14 15:45:59     1.67
+++ src/url.c   2001/12/19 17:53:24
@@ -1173,9 +1173,8 @@
 static char *
 mkstruct (const struct url *u)
 {
-  char *dir, *dir_preencoding;
+  char *dir;
   char *file, *res, *dirpref;
-  char *query = u->query && *u->query ? u->query : NULL;
   int l;
 
   if (opt.cut_dirs)
@@ -1229,9 +1228,6 @@
       dir = newdir;
     }
 
-  dir_preencoding = dir;
-  dir = reencode_string (dir_preencoding);
-
   l = strlen (dir);
   if (l && dir[l - 1] == '/')
     dir[l - 1] = '\0';
@@ -1243,16 +1239,9 @@
 
   /* Finally, construct the full name.  */
   res = (char *)xmalloc (strlen (dir) + 1 + strlen (file)
-                        + (query ? (1 + strlen (query)) : 0)
                         + 1);
   sprintf (res, "%s%s%s", dir, *dir ? "/" : "", file);
-  if (query)
-    {
-      strcat (res, "?");
-      strcat (res, query);
-    }
-  if (dir != dir_preencoding)
-    xfree (dir);
+
   return res;
 }
 
@@ -1319,26 +1308,25 @@
 url_filename (const struct url *u)
 {
   char *file, *name;
-  int have_prefix = 0;         /* whether we must prepend opt.dir_prefix */
 
+  char *query = u->query && *u->query ? u->query : NULL;
+
   if (opt.dirstruct)
     {
-      file = mkstruct (u);
-      have_prefix = 1;
+      char *base = mkstruct (u);
+      file = compose_file_name (base, query);
+      xfree (base);
     }
   else
     {
       char *base = *u->file ? u->file : "index.html";
-      char *query = u->query && *u->query ? u->query : NULL;
       file = compose_file_name (base, query);
-    }
 
-  if (!have_prefix)
-    {
       /* Check whether the prefix directory is something other than "."
         before prepending it.  */
       if (!DOTP (opt.dir_prefix))
        {
+         /* #### should just realloc FILE and prepend dir_prefix. */
          char *nfile = (char *)xmalloc (strlen (opt.dir_prefix)
                                         + 1 + strlen (file) + 1);
          sprintf (nfile, "%s/%s", opt.dir_prefix, file);
@@ -1346,6 +1334,7 @@
          file = nfile;
        }
     }
+
   /* DOS-ish file systems don't like `%' signs in them; we change it
      to `@'.  */
 #ifdef WINDOWS

Reply via email to