diff --git a/src/main.c b/src/main.c index 69df08a7..8b9c1105 100644 --- a/src/main.c +++ b/src/main.c @@ -1203,7 +1203,13 @@ WARNING: Can't reopen standard output in binary mode;\n\ { char *filename = NULL, *redirected_URL = NULL; int dt, url_err; - struct url *url_parsed = url_parse (*t, &url_err, NULL, false); + /* Need to do a new struct iri every time, because + * retrieve_url may modify it in some circumstances, + * currently. */ + struct iri *iri = iri_new (); + struct url *url_parsed = url_parse (*t, &url_err, iri, true); + + set_uri_encoding (iri, opt.locale, true); if (!url_parsed) { @@ -1229,11 +1235,8 @@ WARNING: Can't reopen standard output in binary mode;\n\ } else { - struct iri *i = iri_new (); - set_uri_encoding (i, opt.locale, true); status = retrieve_url (url_parsed, *t, &filename, &redirected_URL, - NULL, &dt, opt.recursive, i); - iri_free (i); + NULL, &dt, opt.recursive, iri); } if (opt.delete_after && file_exists_p(filename)) @@ -1247,6 +1250,7 @@ WARNING: Can't reopen standard output in binary mode;\n\ xfree_null (filename); url_free (url_parsed); } + iri_free (iri); } /* And then from the input file, if any. */ diff --git a/src/recur.c b/src/recur.c index 83a9b4ee..e4ffa424 100644 --- a/src/recur.c +++ b/src/recur.c @@ -278,7 +278,7 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi) { int dt = 0, url_err; char *redirected = NULL; - struct url *url_parsed = url_parse (url, &url_err, i, false); + struct url *url_parsed = url_parse (url, &url_err, i, true); status = retrieve_url (url_parsed, url, &file, &redirected, referer, &dt, false, i); @@ -373,7 +373,7 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi) if (children) { struct urlpos *child = children; - struct url *url_parsed = url_parse (url, NULL, i, false); + struct url *url_parsed = url_parse (url, NULL, i, true); struct iri *ci; char *referer_url = url; bool strip_auth = (url_parsed != NULL diff --git a/src/retr.c b/src/retr.c index 0fd936d0..2a9dec7b 100644 --- a/src/retr.c +++ b/src/retr.c @@ -796,8 +796,18 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file, if (!(*dt & RETROKF) && iri->utf8_encode) { iri->utf8_encode = false; - DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url))); - goto second_try; + if (orig_parsed != u) + { + url_free (u); + } + u = url_parse (origurl, NULL, iri, true); + if (u) + { + DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url))); + goto second_try; + } + else + DEBUGP (("[Couldn't fallback to non-utf8 for %s\n", quote (url))); } if (local_file && *dt & RETROKF)