1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Don't unescape URL escapes twice.

This commit is contained in:
hniksic 2003-10-30 07:42:52 -08:00
parent 29e36b051b
commit 448a61fb83
2 changed files with 32 additions and 19 deletions

View File

@ -1,3 +1,10 @@
2003-10-30 Hrvoje Niksic <hniksic@xemacs.org>
* url.c (append_uri_pathel): New argument ESCAPED_P that says
whether [B, E) is to be treated as URL-escaped or not. If
ESCAPED_P is false, don't unescape the region.
(url_file_name): u->file is not URL-escaped.
2003-10-30 Hrvoje Niksic <hniksic@xemacs.org> 2003-10-30 Hrvoje Niksic <hniksic@xemacs.org>
* retr.c (retrieve_from_file): Use retrieve_tree for * retr.c (retrieve_from_file): Use retrieve_tree for

View File

@ -1427,14 +1427,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 /* Quote path element, characters in [b, e), as file name, and append
the quoted string to DEST. Each character is quoted as per 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 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; const char *p;
int quoted, outlen; int quoted, outlen;
@ -1447,32 +1448,37 @@ append_uri_pathel (const char *b, const char *e, struct growable *dest)
mask |= filechr_control; mask |= filechr_control;
/* Copy [b, e) to PATHEL and URL-unescape it. */ /* Copy [b, e) to PATHEL and URL-unescape it. */
BOUNDED_TO_ALLOCA (b, e, pathel); if (escaped_p)
url_unescape (pathel); {
pathlen = strlen (pathel); 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 /* Walk the PATHEL string and check how many characters we'll need
add for file quoting. */ to add for file quoting. */
quoted = 0; quoted = 0;
for (p = pathel; *p; p++) for (p = b; p < e; p++)
if (FILE_CHAR_TEST (*p, mask)) if (FILE_CHAR_TEST (*p, mask))
++quoted; ++quoted;
/* p - pathel is the string length. Each quoted char means two /* e-b is the string length. Each quoted char means two additional
additional characters in the string, hence 2*quoted. */ characters in the string, hence 2*quoted. */
outlen = (p - pathel) + (2 * quoted); outlen = (e - b) + (2 * quoted);
GROW (dest, outlen); GROW (dest, outlen);
if (!quoted) if (!quoted)
{ {
/* If there's nothing to quote, we don't need to go through the /* If there's nothing to quote, we don't need to go through the
string the second time. */ string the second time. */
memcpy (TAIL (dest), pathel, outlen); memcpy (TAIL (dest), b, outlen);
} }
else else
{ {
char *q = TAIL (dest); char *q = TAIL (dest);
for (p = pathel; *p; p++) for (p = b; p < e; p++)
{ {
if (!FILE_CHAR_TEST (*p, mask)) if (!FILE_CHAR_TEST (*p, mask))
*q++ = *p; *q++ = *p;
@ -1523,7 +1529,7 @@ append_dir_structure (const struct url *u, struct growable *dest)
if (dest->tail) if (dest->tail)
append_char ('/', dest); append_char ('/', dest);
append_uri_pathel (pathel, next, dest); append_uri_pathel (pathel, next, 1, dest);
} }
} }
@ -1572,14 +1578,14 @@ url_file_name (const struct url *u)
if (fnres.tail) if (fnres.tail)
append_char ('/', &fnres); append_char ('/', &fnres);
u_file = *u->file ? u->file : "index.html"; 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. */ /* Append "?query" to the file name. */
u_query = u->query && *u->query ? u->query : NULL; u_query = u->query && *u->query ? u->query : NULL;
if (u_query) if (u_query)
{ {
append_char (FN_QUERY_SEP, &fnres); 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. */ /* Zero-terminate the file name. */