* the source URL accordingly.
* URL encoding should be skipped for host names, otherwise IDN resolution
* will fail.
+ *
+ * Returns TRUE if something was updated.
*/
-static void strcpy_url(char *output, const char *url, bool relative)
+static bool strcpy_url(char *output, const char *url, bool relative)
{
/* we must add this with whitespace-replacing */
bool left = TRUE;
const unsigned char *iptr;
char *optr = output;
const unsigned char *host_sep = (const unsigned char *) url;
+ bool changed = FALSE;
if(!relative)
host_sep = (const unsigned char *) find_host_sep(url);
}
else
*optr++='+'; /* add a '+' here */
+ changed = TRUE;
continue;
}
if(urlchar_needs_escaping(*iptr)) {
msnprintf(optr, 4, "%%%02x", *iptr);
+ changed = TRUE;
optr += 3;
}
else
}
*optr = 0; /* null-terminate output buffer */
+ return changed;
}
/*
}
*part = decoded;
}
+ if(urlencode) {
+ /* worst case output length is 3x the original! */
+ char *newp = malloc(strlen(*part) * 3);
+ if(!newp)
+ return CURLUE_OUT_OF_MEMORY;
+ if(strcpy_url(newp, *part, TRUE)) { /* consider it relative */
+ free(*part);
+ *part = newp;
+ }
+ else
+ free(newp);
+ }
+
return CURLUE_OK;
}
else