]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #1220: Title in FTP listings somewhat messed up
authorserassio <>
Sun, 26 Jun 2005 23:12:47 +0000 (23:12 +0000)
committerserassio <>
Sun, 26 Jun 2005 23:12:47 +0000 (23:12 +0000)
Show FTP URLs in decoded form to allow for national
characters etc to be displayed in a sane manner.

Forward port of 2.5 patch.

src/ftp.cc

index f16bb74c0d0155c9621a4686e63e79b7788f0b60..0efcd00e3172e59845aa65b49d1e2879d0bdca92 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.362 2005/05/01 08:11:48 serassio Exp $
+ * $Id: ftp.cc,v 1.363 2005/06/26 17:12:47 serassio Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -472,15 +472,20 @@ ftpListingStart(FtpStateData * ftpState)
     wordlist *w;
     char *dirup;
     int i, j, k;
-    char *title;
+    const char *title = ftpState->title_url.buf();
     storeBuffer(e);
     storeAppendPrintf(e, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
     storeAppendPrintf(e, "<!-- HTML listing generated by Squid %s -->\n",
                       version_string);
     storeAppendPrintf(e, "<!-- %s -->\n", mkrfc1123(squid_curtime));
     storeAppendPrintf(e, "<HTML><HEAD><TITLE>\n");
-    storeAppendPrintf(e, "FTP Directory: %s\n",
-                      html_quote(ftpState->title_url.buf()));
+    {
+        char *t = xstrdup(title);
+        rfc1738_unescape(t);
+        storeAppendPrintf(e, "FTP Directory: %s\n", html_quote(t));
+        xfree(t);
+    }
+
     storeAppendPrintf(e, "</TITLE>\n");
     storeAppendPrintf(e, "<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE>\n");
 
@@ -507,36 +512,34 @@ ftpListingStart(FtpStateData * ftpState)
     storeAppendPrintf(e, "FTP Directory: ");
     /* "ftp://" == 6 characters */
     assert(ftpState->title_url.size() >= 6);
-    title = html_quote(ftpState->title_url.buf());
+    k = 6 + strcspn(&title[6], "/");
 
     for (i = 6, j = 0; title[i]; j = i) {
         storeAppendPrintf(e, "<A HREF=\"");
         i += strcspn(&title[i], "/");
 
-        if (title[i] == '/')
-            i++;
-
-        for (k = 0; k < i; k++)
-            storeAppendPrintf(e, "%c", title[k]);
-
-        storeAppendPrintf(e, "\">");
-
-        for (k = j; k < i - 1; k++)
-            storeAppendPrintf(e, "%c", title[k]);
-
-        if (ftpState->title_url.buf()[k] != '/')
-            storeAppendPrintf(e, "%c", title[k++]);
+        if (i > j) {
+            char *url = xstrdup(title);
+            url[i] = '\0';
+            storeAppendPrintf(e, "%s", html_quote(url + k));
+            storeAppendPrintf(e, "/");
+            storeAppendPrintf(e, "\">");
+            rfc1738_unescape(url + j);
+            storeAppendPrintf(e, "%s", html_quote(url + j));
+            safe_free(url);
+            storeAppendPrintf(e, "</A>");
+        }
 
-        storeAppendPrintf(e, "</A>");
+        storeAppendPrintf(e, "/");
 
-        if (k < i)
-            storeAppendPrintf(e, "%c", title[k++]);
+        if (title[i] == '/')
+            i++;
 
         if (i == j) {
             /* Error guard, or "assert" */
             storeAppendPrintf(e, "ERROR: Failed to parse URL: %s\n",
-                              html_quote(ftpState->title_url.buf()));
-            debug(9, 0) ("Failed to parse URL: %s\n", ftpState->title_url.buf());
+                              html_quote(title));
+            debug(9, 0) ("Failed to parse URL: %s\n", title);
             break;
         }
     }