X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Furl.c;h=32de9c751fdc358e94ed9422d2d191493b7a0949;hb=9a2ea3938d09643c6528c3b83b1db4c30f47d981;hp=87ba3cc9dc3e848b6617bb2680f9f90d99d14a5a;hpb=e72b57629bf49cdfd663002a8bb336a67b958979;p=wget diff --git a/src/url.c b/src/url.c index 87ba3cc9..32de9c75 100644 --- a/src/url.c +++ b/src/url.c @@ -42,6 +42,7 @@ as that of the covered work. */ #include "utils.h" #include "url.h" #include "host.h" /* for is_valid_ipv6_address */ +#include "iri.h" #ifdef TESTING #include "test.h" @@ -640,7 +641,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, bool *utf8_encode) { struct url *u; const char *p; @@ -670,6 +671,15 @@ url_parse (const char *url, int *error) goto error; } + if (opt.enable_iri && *utf8_encode) + { + const char *new; + url_unescape ((char *) url); + *utf8_encode = remote_to_utf8 (url, &new); + if (*utf8_encode) + url = new; + } + url_encoded = reencode_escapes (url); p = url_encoded; @@ -844,6 +854,17 @@ url_parse (const char *url, int *error) host_modified = true; } + if (opt.enable_iri) + { + char *new = idn_encode (u->host, *utf8_encode); + if (new) + { + xfree (u->host); + u->host = new; + host_modified = true; + } + } + if (params_b) u->params = strdupdelim (params_b, params_e); if (query_b) @@ -851,7 +872,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 +910,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]); }