]> sjero.net Git - wget/commitdiff
Applied Alexander Belopolsky's patch for htmlified FTP listings.
authorMicah Cowan <micah@cowan.name>
Thu, 13 Nov 2008 04:47:52 +0000 (20:47 -0800)
committerMicah Cowan <micah@cowan.name>
Thu, 13 Nov 2008 04:47:52 +0000 (20:47 -0800)
src/ChangeLog
src/ftp-ls.c
src/url.c
src/url.h

index 27f2987468b9c25031bab29cd509dbf2455a7856..da701d6c0a88bf45ec782046203bded608022605 100644 (file)
@@ -1,3 +1,10 @@
+2008-11-12  Alexander Belopolsky  <alexander.belopolsky@gmail.com>
+
+       * url.c, url.h (url_escape_unsafe_and_reserved): Added.
+
+       * ftp-ls.c (ftp_index): URL-escape, rather than HTML-escape, the
+       filename appearing in the link.
+
 2008-11-12  Steven Schubiger  <stsc@members.fsf.org>
 
        * main.c (print_version): Hand the relevant
 2008-11-12  Steven Schubiger  <stsc@members.fsf.org>
 
        * main.c (print_version): Hand the relevant
index 660302e5b33a51ad8178a3bf30181b4cef47c5d4..dd6caa661273b1fb422d0fd6157d9a06ea5feab7 100644 (file)
@@ -851,6 +851,7 @@ ftp_index (const char *file, struct url *u, struct fileinfo *f)
   FILE *fp;
   char *upwd;
   char *htclfile;               /* HTML-clean file name */
   FILE *fp;
   char *upwd;
   char *htclfile;               /* HTML-clean file name */
+  char *urlclfile;              /* URL-clean file name */
 
   if (!output_stream)
     {
 
   if (!output_stream)
     {
@@ -923,13 +924,14 @@ ftp_index (const char *file, struct url *u, struct fileinfo *f)
           break;
         }
       htclfile = html_quote_string (f->name);
           break;
         }
       htclfile = html_quote_string (f->name);
+      urlclfile = url_escape_unsafe_and_reserved (f->name);
       fprintf (fp, "<a href=\"ftp://%s%s:%d", upwd, u->host, u->port);
       if (*u->dir != '/')
         putc ('/', fp);
       fprintf (fp, "%s", u->dir);
       if (*u->dir)
         putc ('/', fp);
       fprintf (fp, "<a href=\"ftp://%s%s:%d", upwd, u->host, u->port);
       if (*u->dir != '/')
         putc ('/', fp);
       fprintf (fp, "%s", u->dir);
       if (*u->dir)
         putc ('/', fp);
-      fprintf (fp, "%s", htclfile);
+      fprintf (fp, "%s", urlclfile);
       if (f->type == FT_DIRECTORY)
         putc ('/', fp);
       fprintf (fp, "\">%s", htclfile);
       if (f->type == FT_DIRECTORY)
         putc ('/', fp);
       fprintf (fp, "\">%s", htclfile);
@@ -942,6 +944,7 @@ ftp_index (const char *file, struct url *u, struct fileinfo *f)
         fprintf (fp, "-> %s", f->linkto ? f->linkto : "(nil)");
       putc ('\n', fp);
       xfree (htclfile);
         fprintf (fp, "-> %s", f->linkto ? f->linkto : "(nil)");
       putc ('\n', fp);
       xfree (htclfile);
+      xfree (urlclfile);
       f = f->next;
     }
   fprintf (fp, "</pre>\n</body>\n</html>\n");
       f = f->next;
     }
   fprintf (fp, "</pre>\n</body>\n</html>\n");
index fea95584626705000ad32d0d0a126fb83a1ee028..d416fcf7fae38e6ee5b19276773ace45425d41a5 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -252,6 +252,15 @@ url_escape (const char *s)
   return url_escape_1 (s, urlchr_unsafe, false);
 }
 
   return url_escape_1 (s, urlchr_unsafe, false);
 }
 
+/* URL-escape the unsafe and reserved characters (see urlchr_table) in
+   a given string, returning a freshly allocated string.  */
+
+char *
+url_escape_unsafe_and_reserved (const char *s)
+{
+  return url_escape_1 (s, urlchr_unsafe|urlchr_reserved, false);
+}
+
 /* URL-escape the unsafe characters (see urlchr_table) in a given
    string.  If no characters are unsafe, S is returned.  */
 
 /* URL-escape the unsafe characters (see urlchr_table) in a given
    string.  If no characters are unsafe, S is returned.  */
 
index ce308f6f97d815c624e85dd5ecc78a9300af83d6..f523e2efd3229104515e4825b29e0559c83503fc 100644 (file)
--- a/src/url.h
+++ b/src/url.h
@@ -83,6 +83,7 @@ struct url
 /* Function declarations */
 
 char *url_escape (const char *);
 /* Function declarations */
 
 char *url_escape (const char *);
+char *url_escape_unsafe_and_reserved (const char *);
 
 struct url *url_parse (const char *, int *);
 char *url_error (const char *, int);
 
 struct url *url_parse (const char *, int *);
 char *url_error (const char *, int);