]> sjero.net Git - wget/blobdiff - src/url.c
Quote some things that needed quoting.
[wget] / src / url.c
index c937d05695e03ede8d38dc79dd2bcb01632427d9..6b24e0637331c0fa28e9e5fa96a24ee6667b64ee 100644 (file)
--- 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.  */
 
@@ -640,7 +649,7 @@ static const char *parse_errors[] = {
    error, and if ERROR is not NULL, also set *ERROR to the appropriate
    error code. */
 struct url *
-url_parse (const char *url, int *error, struct iri *iri)
+url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
 {
   struct url *u;
   const char *p;
@@ -659,7 +668,8 @@ url_parse (const char *url, int *error, struct iri *iri)
   int port;
   char *user = NULL, *passwd = NULL;
 
-  char *url_encoded = NULL, *new_url = NULL;
+  const char *url_encoded = NULL;
+  char *new_url = NULL;
 
   int error_code;
 
@@ -672,13 +682,19 @@ url_parse (const char *url, int *error, struct iri *iri)
 
   if (iri && iri->utf8_encode)
     {
-      url_unescape ((char *) url);
-      iri->utf8_encode = remote_to_utf8 (iri, url, (const char **) &new_url);
+      iri->utf8_encode = remote_to_utf8 (iri, iri->orig_url ? iri->orig_url : url, (const char **) &new_url);
       if (!iri->utf8_encode)
         new_url = NULL;
+      else
+        iri->orig_url = xstrdup (url);
     }
 
-  url_encoded = reencode_escapes (new_url ? new_url : url);
+  /* XXX XXX Could that change introduce (security) bugs ???  XXX XXX*/
+  if (percent_encode)
+    url_encoded = reencode_escapes (new_url ? new_url : url);
+  else
+    url_encoded = new_url ? new_url : url;
+
   p = url_encoded;
 
   if (new_url && url_encoded != new_url)
@@ -889,7 +905,7 @@ url_parse (const char *url, int *error, struct iri *iri)
       if (url_encoded == url)
         u->url = xstrdup (url);
       else
-        u->url = url_encoded;
+        u->url = (char *) url_encoded;
     }
 
   return u;
@@ -897,7 +913,7 @@ url_parse (const char *url, int *error, struct iri *iri)
  error:
   /* Cleanup in case of error: */
   if (url_encoded && url_encoded != url)
-    xfree (url_encoded);
+    xfree ((char *) url_encoded);
 
   /* Transmit the error code to the caller, if the caller wants to
      know.  */
@@ -923,9 +939,9 @@ url_error (const char *url, int error_code)
       if ((p = strchr (scheme, ':')))
         *p = '\0';
       if (!strcasecmp (scheme, "https"))
-        asprintf (&error, _("HTTPS support not compiled in"));
+        error = aprintf (_("HTTPS support not compiled in"));
       else
-        asprintf (&error, _(parse_errors[error_code]), quote (scheme));
+        error = aprintf (_(parse_errors[error_code]), quote (scheme));
       xfree (scheme);
 
       return error;
@@ -1992,12 +2008,12 @@ schemes_are_similar_p (enum url_scheme a, enum url_scheme b)
 \f
 static int
 getchar_from_escaped_string (const char *str, char *c)
-{  
+{
   const char *p = str;
 
   assert (str && *str);
   assert (c);
-  
+
   if (p[0] == '%')
     {
       if (!c_isxdigit(p[1]) || !c_isxdigit(p[2]))
@@ -2047,7 +2063,7 @@ are_urls_equal (const char *u1, const char *u2)
       p += pp;
       q += qq;
     }
-  
+
   return (*p == 0 && *q == 0 ? true : false);
 }
 \f
@@ -2156,7 +2172,7 @@ test_append_uri_pathel()
   } test_array[] = {
     { "http://www.yoyodyne.com/path/", "somepage.html", false, "http://www.yoyodyne.com/path/somepage.html" },
   };
-  
+
   for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i) 
     {
       struct growable dest;