]> sjero.net Git - wget/blobdiff - src/retr.c
IRI requirement: do not percent-encode already percent-encoded values (try1)
[wget] / src / retr.c
index 963d50442b3cb861ca89ca36bf6be36f9a3816e2..fe4e3e76c0d30a07d1067de2a583020bda1883e5 100644 (file)
@@ -626,16 +626,18 @@ retrieve_url (const char *origurl, char **file, char **newloc,
     *file = NULL;
 
  second_try:
-  u = url_parse (url, &up_error_code, iri);
+  u = url_parse (url, &up_error_code, iri, true);
   if (!u)
     {
-      logprintf (LOG_NOTQUIET, "%s: %s.\n", url, url_error (up_error_code));
+      char *error = url_error (url, up_error_code);
+      logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error);
       xfree (url);
+      xfree (error);
       return URLERROR;
     }
 
-  DEBUGP (("[IRI Retrieving %s with %s (UTF-8=%d)\n", quote (url),
-           iri->uri_encoding ? quote (iri->uri_encoding) : "None",
+  DEBUGP (("[IRI Retrieving %s with %s (UTF-8=%d)\n", quote_n (0, url),
+           iri->uri_encoding ? quote_n (1, iri->uri_encoding) : "None",
            iri->utf8_encode));
 
   if (!refurl)
@@ -656,12 +658,14 @@ retrieve_url (const char *origurl, char **file, char **newloc,
       pi->utf8_encode = false;
 
       /* Parse the proxy URL.  */
-      proxy_url = url_parse (proxy, &up_error_code, NULL);
+      proxy_url = url_parse (proxy, &up_error_code, NULL, true);
       if (!proxy_url)
         {
+          char *error = url_error (proxy, up_error_code);
           logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
-                     proxy, url_error (up_error_code));
+                     proxy, error);
           xfree (url);
+          xfree (error);
           RESTORE_POST_DATA;
           return PROXERR;
         }
@@ -735,16 +739,19 @@ retrieve_url (const char *origurl, char **file, char **newloc,
          the content encoding. */
       iri->utf8_encode = opt.enable_iri;
       set_content_encoding (iri, NULL);
+      xfree_null (iri->orig_url);
 
       /* Now, see if this new location makes sense. */
-      newloc_parsed = url_parse (mynewloc, &up_error_code, iri);
+      newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true);
       if (!newloc_parsed)
         {
+          char *error = url_error (mynewloc, up_error_code);
           logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc),
-                     url_error (up_error_code));
+                     error);
           url_free (u);
           xfree (url);
           xfree (mynewloc);
+          xfree (error);
           RESTORE_POST_DATA;
           return result;
         }
@@ -788,7 +795,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   if (!(*dt & RETROKF) && iri->utf8_encode)
     {
       iri->utf8_encode = false;
-      DEBUGP (("[IRI Fallbacking to non-utf8 for %s\n", quote (url)));
+      DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url)));
       goto second_try;
     }
 
@@ -874,6 +881,10 @@ retrieve_from_file (const char *file, bool html, int *count)
 
       if (dt & TEXTHTML)
         html = true;
+
+      /* If we have a found a content encoding, use it */
+      if (iri->content_encoding)
+         set_uri_encoding (iri, iri->content_encoding, false);
     }
   else
     input_file = (char *) file;
@@ -897,6 +908,8 @@ retrieve_from_file (const char *file, bool html, int *count)
 
       /* Reset UTF-8 encode status */
       iri->utf8_encode = opt.enable_iri;
+      xfree_null (iri->orig_url);
+      iri->orig_url = NULL;
 
       if ((opt.recursive || opt.page_requisites)
           && (cur_url->url->scheme != SCHEME_FTP || getproxy (cur_url->url)))
@@ -1090,7 +1103,7 @@ url_uses_proxy (const char *url)
   struct iri *i = iri_new();
   /* url was given in the command line, so use locale as encoding */
   set_uri_encoding (i, opt.locale, true);
-  u= url_parse (url, NULL, i);
+  u= url_parse (url, NULL, i, false);
   if (!u)
     return false;
   ret = getproxy (u) != NULL;