]> sjero.net Git - wget/commitdiff
Automated merge.
authorMicah Cowan <micah@cowan.name>
Mon, 1 Dec 2008 15:05:29 +0000 (07:05 -0800)
committerMicah Cowan <micah@cowan.name>
Mon, 1 Dec 2008 15:05:29 +0000 (07:05 -0800)
1  2 
src/retr.c
src/url.c
src/url.h
tests/Test-iri.px

diff --combined src/retr.c
index fe4e3e76c0d30a07d1067de2a583020bda1883e5,e3d62978f0b1ee4ea38adb1e36358794f4f2f82b..1d9d74782126dcd9e134a0f7e421e2edd903e384
@@@ -393,7 -393,7 +393,7 @@@ fd_read_hunk (int fd, hunk_terminator_
    char *hunk = xmalloc (bufsize);
    int tail = 0;                 /* tail position in HUNK */
  
-   assert (maxsize >= bufsize);
+   assert (!maxsize || maxsize >= bufsize);
  
    while (1)
      {
@@@ -626,7 -626,7 +626,7 @@@ retrieve_url (const char *origurl, cha
      *file = NULL;
  
   second_try:
 -  u = url_parse (url, &up_error_code, iri);
 +  u = url_parse (url, &up_error_code, iri, true);
    if (!u)
      {
        char *error = url_error (url, up_error_code);
        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);
           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);
    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;
      }
  
@@@ -908,8 -907,6 +908,8 @@@ retrieve_from_file (const char *file, b
  
        /* 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)))
@@@ -1103,7 -1100,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;
diff --combined src/url.c
index 8f0672503f07fdfef8cde9b8b4093b4b63841c71,31614794cfd3411614b708939264653a1d284546..86d099a7190b80aaec8bc1cf6771c49892364602
+++ b/src/url.c
@@@ -252,6 -252,15 +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 +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;
  
    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)
@@@ -929,9 -932,9 +938,9 @@@ url_error (const char *url, int error_c
        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;
@@@ -1998,12 -2001,12 +2007,12 @@@ schemes_are_similar_p (enum url_scheme 
  \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]))
@@@ -2053,7 -2056,7 +2062,7 @@@ are_urls_equal (const char *u1, const c
        p += pp;
        q += qq;
      }
 -  
 +
    return (*p == 0 && *q == 0 ? true : false);
  }
  \f
@@@ -2162,7 -2165,7 +2171,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;
diff --combined src/url.h
index 2fa8d51cd0d64b3687b54ff16e9b064404c9aae9,badd92522b90fc39e2b956fd111be9497a431d78..38eafca4b50997aebba6a5f92574c34a93ad0248
+++ b/src/url.h
@@@ -83,8 -83,9 +83,9 @@@ struct ur
  /* Function declarations */
  
  char *url_escape (const char *);
+ char *url_escape_unsafe_and_reserved (const char *);
  
 -struct url *url_parse (const char *, int *, struct iri *iri);
 +struct url *url_parse (const char *, int *, struct iri *iri, bool percent_encode);
  char *url_error (const char *, int);
  char *url_full_path (const struct url *);
  void url_set_dir (struct url *, const char *);
diff --combined tests/Test-iri.px
index ca6feddfbedccb455fd031191f3257df8e50dfe1,662019e794a3d63ddbe02967ae8c37ba041b93c8..738c304a95fa82ceef274c40b2a6fe5e1661dcef
@@@ -1,6 -1,7 +1,7 @@@
- #!/usr/bin/perl -w
+ #!/usr/bin/perl
  
  use strict;
+ use warnings;
  
  use HTTPTest;
  
@@@ -214,9 -215,9 +215,9 @@@ my %expected_downloaded_files = 
  ###############################################################################
  
  my $the_test = HTTPTest->new (name => "Test-iri",
 -                              input => \%urls, 
 -                              cmdline => $cmdline, 
 -                              errcode => $expected_error_code, 
 +                              input => \%urls,
 +                              cmdline => $cmdline,
 +                              errcode => $expected_error_code,
                                output => \%expected_downloaded_files);
  exit $the_test->run();