X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Furl.c;h=e79cf8a2e0736688c0ce1495adc7d7b48286946c;hb=84395897ad2d1c107be470946daba744b2e7ebe8;hp=87ba3cc9dc3e848b6617bb2680f9f90d99d14a5a;hpb=e72b57629bf49cdfd663002a8bb336a67b958979;p=wget diff --git a/src/url.c b/src/url.c index 87ba3cc9..e79cf8a2 100644 --- a/src/url.c +++ b/src/url.c @@ -640,7 +640,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) +url_parse (const char *url, int *error, struct iri *iri) { struct url *u; const char *p; @@ -659,7 +659,7 @@ url_parse (const char *url, int *error) int port; char *user = NULL, *passwd = NULL; - char *url_encoded = NULL; + char *url_encoded = NULL, *new_url = NULL; int error_code; @@ -670,9 +670,20 @@ url_parse (const char *url, int *error) goto error; } - url_encoded = reencode_escapes (url); + if (iri && iri->utf8_encode) + { + url_unescape ((char *) url); + iri->utf8_encode = remote_to_utf8 (iri, url, (const char **) &new_url); + if (!iri->utf8_encode) + new_url = NULL; + } + + url_encoded = reencode_escapes (new_url ? new_url : url); p = url_encoded; + if (new_url && url_encoded != new_url) + xfree (new_url); + p += strlen (supported_schemes[scheme].leading_string); uname_b = p; p = url_skip_credentials (p); @@ -842,6 +853,18 @@ url_parse (const char *url, int *error) { url_unescape (u->host); host_modified = true; + + /* Apply IDNA regardless of iri->utf8_encode status */ + if (opt.enable_iri && iri) + { + char *new = idn_encode (iri, u->host); + if (new) + { + xfree (u->host); + u->host = new; + host_modified = true; + } + } } if (params_b) @@ -851,7 +874,7 @@ url_parse (const char *url, int *error) if (fragment_b) u->fragment = strdupdelim (fragment_b, fragment_e); - if (path_modified || u->fragment || host_modified || path_b == path_e) + if (opt.enable_iri || path_modified || u->fragment || host_modified || path_b == path_e) { /* If we suspect that a transformation has rendered what url_string might return different from URL_ENCODED, rebuild @@ -889,7 +912,7 @@ url_parse (const char *url, int *error) const char * url_error (int error_code) { - assert (error_code >= 0 && error_code < countof (parse_errors)); + assert (error_code >= 0 && ((size_t) error_code) < countof (parse_errors)); return _(parse_errors[error_code]); }