From e986f7dad37b15fd382b02c93507046e017ba759 Mon Sep 17 00:00:00 2001
From: hniksic <devnull@localhost>
Date: Tue, 4 Dec 2001 01:49:37 -0800
Subject: [PATCH] [svn] Quote '?' as '%3F' in local files when
 `--html-extension' is turned on. Published in
 <sxszo4ztiwr.fsf@florida.arsdigita.de>.

---
 src/ChangeLog |  5 +++++
 src/url.c     | 36 +++++++++++++++---------------------
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 2ed0bd4a..496f4623 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2001-12-04  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+	* url.c (local_quote_string): Reenable quoting of question marks,
+	but only when `--html-extension' is used.
+
 2001-12-03  Hrvoje Niksic  <hniksic@arsdigita.com>
 
 	* snprintf.c (dopr): Cast the result of va_arg to short int and
diff --git a/src/url.c b/src/url.c
index fde1a412..f8ddbeb9 100644
--- a/src/url.c
+++ b/src/url.c
@@ -2097,32 +2097,27 @@ find_fragment (const char *beg, int size, const char **bp, const char **ep)
   return 0;
 }
 
-/* The idea here was to quote ? as %3F to avoid passing part of the
-   file name as the parameter when browsing the converted file through
-   HTTP.  However, actually doing that breaks local browsing because
-   "index.html%3Ffoo=bar" isn't even recognized as an HTML file!
-   Perhaps this should be controlled by an option, but for now I'm
-   leaving the question marks.
+/* Quote FILE for use as local reference to an HTML file.
 
-   This is the original docstring of this function:
-
-   FILE should be a relative link to a local file.  It should be
-   quoted as HTML because it will be used in HTML context.  However,
-   we need to quote ? as %3F to avoid passing part of the file name as
-   the parameter.  (This is not a problem when viewing locally, but is
-   if the downloaded and converted tree is served by an HTTP
-   server.)  */
-
-/* Quote string as HTML. */
+   We quote ? as %3F to avoid passing part of the file name as the
+   parameter when browsing the converted file through HTTP.  However,
+   it is safe to do this only when `--html-extension' is turned on.
+   This is because converting "index.html?foo=bar" to
+   "index.html%3Ffoo=bar" would break local browsing, as the latter
+   isn't even recognized as an HTML file!  However, converting
+   "index.html?foo=bar.html" to "index.html%3Ffoo=bar.html" should be
+   safe for both local and HTTP-served browsing.  */
 
 static char *
 local_quote_string (const char *file)
 {
-  return html_quote_string (file);
-
-#if 0
   const char *file_sans_qmark;
-  int qm = count_char (file, '?');
+  int qm;
+
+  if (!opt.html_extension)
+    return html_quote_string (file);
+
+  qm = count_char (file, '?');
 
   if (qm)
     {
@@ -2154,7 +2149,6 @@ local_quote_string (const char *file)
     file_sans_qmark = file;
 
   return html_quote_string (file_sans_qmark);
-#endif
 }
 
 /* We're storing "modes" of type downloaded_file_t in the hash table.