From cf93ce7f4b428c78ca705f0f905ba75bbb2806d5 Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Wed, 12 Nov 2008 20:47:52 -0800 Subject: [PATCH] Applied Alexander Belopolsky's patch for htmlified FTP listings. --- src/ChangeLog | 7 +++++++ src/ftp-ls.c | 5 ++++- src/url.c | 9 +++++++++ src/url.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 27f29874..da701d6c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2008-11-12 Alexander Belopolsky + + * 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 * main.c (print_version): Hand the relevant diff --git a/src/ftp-ls.c b/src/ftp-ls.c index 660302e5..dd6caa66 100644 --- a/src/ftp-ls.c +++ b/src/ftp-ls.c @@ -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 */ + char *urlclfile; /* URL-clean file name */ 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); + urlclfile = url_escape_unsafe_and_reserved (f->name); fprintf (fp, "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); @@ -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); + xfree (urlclfile); f = f->next; } fprintf (fp, "\n\n\n"); diff --git a/src/url.c b/src/url.c index fea95584..d416fcf7 100644 --- 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); } +/* 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. */ diff --git a/src/url.h b/src/url.h index ce308f6f..f523e2ef 100644 --- a/src/url.h +++ b/src/url.h @@ -83,6 +83,7 @@ struct url /* 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); -- 2.39.2