htls: Remember to quote URL characters in filenames.
[ashd.git] / src / htls.c
index 060d1bf..d2db5f4 100644 (file)
@@ -73,7 +73,7 @@ static int dcmp(const void *ap, const void *bp)
 
 static void head(char *name, struct charbuf *dst)
 {
-    char *title, *tmp;
+    char *title;
     
     title = sstrdup(htmlquote(name));
     bprintf(dst, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
@@ -82,7 +82,7 @@ static void head(char *name, struct charbuf *dst)
     bprintf(dst, "<head>\n");
     bprintf(dst, "<title>Index of %s</title>\n", title);
     if(stylesheet) {
-       bprintf(dst, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n", htmlquote(tmp));
+       bprintf(dst, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n", htmlquote(stylesheet));
     } else {
        bprintf(dst, "<style>\n");
        bprintf(dst, "body {font-family: sans-serif; background: #eee;}\n");
@@ -149,8 +149,9 @@ static void mkindex(char *name, DIR *dir, struct charbuf *dst)
        if(dirbuf.b[i].w)
            bprintf(dst, " writable");
        bprintf(dst, "\">");    
-       fn = htmlquote(dirbuf.b[i].name);
-       bprintf(dst, "<td class=\"filename\"><a href=\"%s\">%s</a></td>", fn, fn);
+       bprintf(dst, "<td class=\"filename\"><a href=\"%s\">", htmlquote(urlquote(dirbuf.b[i].name)));
+       bprintf(dst, "%s", htmlquote(dirbuf.b[i].name));
+       bprintf(dst, "</a></td>");
        if(dispsize) {
            bprintf(dst, "<td class=\"filesize\">");
            if(!S_ISDIR(dirbuf.b[i].sb.st_mode))