X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Furl.c;h=40482b75adf6bca8ecf3992f258f7cf26584d232;hb=5f0a2b3f0846dd4c2f72fc62e7171200d1fd6e06;hp=ecb79b9c4c8cfa077d6a2b9c508df2eb6ab8768f;hpb=27d5becdaf815f19fa756ae760077383210a172e;p=wget diff --git a/src/url.c b/src/url.c index ecb79b9c..40482b75 100644 --- a/src/url.c +++ b/src/url.c @@ -971,9 +971,7 @@ url_parse (const char *url, int *error) } } - u = (struct url *)xmalloc (sizeof (struct url)); - memset (u, 0, sizeof (*u)); - + u = xnew0 (struct url); u->scheme = scheme; u->host = strdupdelim (host_b, host_e); u->port = port; @@ -1427,14 +1425,15 @@ UWC, C, C, C, C, C, C, C, /* NUL SOH STX ETX EOT ENQ ACK BEL */ /* Quote path element, characters in [b, e), as file name, and append the quoted string to DEST. Each character is quoted as per - file_unsafe_char and the corresponding table. */ + file_unsafe_char and the corresponding table. + + If ESCAPED_P is non-zero, the path element is considered to be + URL-escaped and will be unescaped prior to inspection. */ static void -append_uri_pathel (const char *b, const char *e, struct growable *dest) +append_uri_pathel (const char *b, const char *e, int escaped_p, + struct growable *dest) { - char *pathel; - int pathlen; - const char *p; int quoted, outlen; @@ -1447,32 +1446,37 @@ append_uri_pathel (const char *b, const char *e, struct growable *dest) mask |= filechr_control; /* Copy [b, e) to PATHEL and URL-unescape it. */ - BOUNDED_TO_ALLOCA (b, e, pathel); - url_unescape (pathel); - pathlen = strlen (pathel); + if (escaped_p) + { + char *unescaped; + BOUNDED_TO_ALLOCA (b, e, unescaped); + url_unescape (unescaped); + b = unescaped; + e = unescaped + strlen (unescaped); + } - /* Go through PATHEL and check how many characters we'll need to - add for file quoting. */ + /* Walk the PATHEL string and check how many characters we'll need + to add for file quoting. */ quoted = 0; - for (p = pathel; *p; p++) + for (p = b; p < e; p++) if (FILE_CHAR_TEST (*p, mask)) ++quoted; - /* p - pathel is the string length. Each quoted char means two - additional characters in the string, hence 2*quoted. */ - outlen = (p - pathel) + (2 * quoted); + /* e-b is the string length. Each quoted char means two additional + characters in the string, hence 2*quoted. */ + outlen = (e - b) + (2 * quoted); GROW (dest, outlen); if (!quoted) { /* If there's nothing to quote, we don't need to go through the string the second time. */ - memcpy (TAIL (dest), pathel, outlen); + memcpy (TAIL (dest), b, outlen); } else { char *q = TAIL (dest); - for (p = pathel; *p; p++) + for (p = b; p < e; p++) { if (!FILE_CHAR_TEST (*p, mask)) *q++ = *p; @@ -1523,7 +1527,7 @@ append_dir_structure (const struct url *u, struct growable *dest) if (dest->tail) append_char ('/', dest); - append_uri_pathel (pathel, next, dest); + append_uri_pathel (pathel, next, 1, dest); } } @@ -1572,14 +1576,14 @@ url_file_name (const struct url *u) if (fnres.tail) append_char ('/', &fnres); u_file = *u->file ? u->file : "index.html"; - append_uri_pathel (u_file, u_file + strlen (u_file), &fnres); + append_uri_pathel (u_file, u_file + strlen (u_file), 0, &fnres); /* Append "?query" to the file name. */ u_query = u->query && *u->query ? u->query : NULL; if (u_query) { append_char (FN_QUERY_SEP, &fnres); - append_uri_pathel (u_query, u_query + strlen (u_query), &fnres); + append_uri_pathel (u_query, u_query + strlen (u_query), 1, &fnres); } /* Zero-terminate the file name. */