I found dir_cgi.c was serving up invalid URLs for a few of my files.
This patch expands the list of characters that need to be escaped.

This patch also calculates file sizes in actual kilobytes (kb, as
displayed) and not kibibytes (kib).  You can omit the second hunk if you
dislike this.

Please consider updating the link on the mathopd homepage with this
patch.  I'd be happy to host a patched version if that's easier for
everyone.

Only in dir_cgi-1.1: dir_cgi
diff -ur dir_cgi-1.1.orig/dir_cgi.c dir_cgi-1.1/dir_cgi.c
--- dir_cgi-1.1.orig/dir_cgi.c  2006-06-23 04:02:13.000000000 -0500
+++ dir_cgi-1.1/dir_cgi.c       2009-02-05 11:13:54.000000000 -0600
@@ -65,6 +65,15 @@
                        printf("%%%02x", c & 0xff); /* ugh */
                else
                        switch (c) {
+                       case ':':
+                               printf("%%3a");
+                               break;
+                       case '/':
+                               printf("%%2f");
+                               break;
+                       case '\\':
+                               printf("%%5c");
+                               break;
                        case '<':
                                printf("&lt;");
                                break;
@@ -162,7 +171,7 @@
        for (i = 0; i < n; i++) {
                if (S_ISREG(p[i].mode)) {
                        printf("%19s ", iso_date(p[i].last_modified));
-                       printf("%10.2lf kB  ", p[i].size/1024.0);
+                       printf("%10.2lf kB  ", p[i].size/1000.0);
                        printf("<a href=\"");
                        escape_url_print(p[i].name);
                        printf("\">");
Only in dir_cgi-1.1: dir_cgi.c~


Reply via email to