mirror of
https://github.com/mirror/wget.git
synced 2025-01-07 19:00:30 +08:00
[svn] Renamed "decide_copy_method" to "char_needs_escaping". Made it return
bool (int).
This commit is contained in:
parent
9bdeaf453d
commit
2e625afe68
@ -1,3 +1,9 @@
|
|||||||
|
2005-05-07 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
|
* url.c (decide_copy_method): Renamed to char_needs_escaping.
|
||||||
|
Since it now returns only two possible values, change it to return
|
||||||
|
boolean (int).
|
||||||
|
|
||||||
2005-05-07 Hrvoje Niksic <hniksic@xemacs.org>
|
2005-05-07 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
* ftp-basic.c (ftp_request): Prevent newlines in VALUE causing
|
* ftp-basic.c (ftp_request): Prevent newlines in VALUE causing
|
||||||
|
63
src/url.c
63
src/url.c
@ -255,29 +255,27 @@ url_escape_allow_passthrough (const char *s)
|
|||||||
return url_escape_1 (s, urlchr_unsafe, 1);
|
return url_escape_1 (s, urlchr_unsafe, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum copy_method { cm_encode, cm_passthrough };
|
/* Decide whether the char at position P needs to be encoded. (It is
|
||||||
|
not enough to pass a single char *P because the function may need
|
||||||
|
to inspect the surrounding context.)
|
||||||
|
|
||||||
/* Decide whether to encode or pass through the char at P. This used
|
Return 1 if the char should be escaped as %XX, 0 otherwise. */
|
||||||
to be a macro, but it got a little too convoluted. */
|
|
||||||
|
|
||||||
static inline enum copy_method
|
static inline int
|
||||||
decide_copy_method (const char *p)
|
char_needs_escaping (const char *p)
|
||||||
{
|
{
|
||||||
if (*p == '%')
|
if (*p == '%')
|
||||||
{
|
{
|
||||||
if (ISXDIGIT (*(p + 1)) && ISXDIGIT (*(p + 2)))
|
if (ISXDIGIT (*(p + 1)) && ISXDIGIT (*(p + 2)))
|
||||||
/* Prior to 1.10 this decoded %HH escapes corresponding to
|
return 0;
|
||||||
"safe" chars, but that proved too obtrusive -- it's better
|
|
||||||
to always preserve the escapes found in the URL. */
|
|
||||||
return cm_passthrough;
|
|
||||||
else
|
else
|
||||||
/* Garbled %.. sequence: encode `%'. */
|
/* Garbled %.. sequence: encode `%'. */
|
||||||
return cm_encode;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (URL_UNSAFE_CHAR (*p) && !URL_RESERVED_CHAR (*p))
|
else if (URL_UNSAFE_CHAR (*p) && !URL_RESERVED_CHAR (*p))
|
||||||
return cm_encode;
|
return 1;
|
||||||
else
|
else
|
||||||
return cm_passthrough;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Translate a %-escaped (but possibly non-conformant) input string S
|
/* Translate a %-escaped (but possibly non-conformant) input string S
|
||||||
@ -368,19 +366,11 @@ reencode_escapes (const char *s)
|
|||||||
|
|
||||||
int encode_count = 0;
|
int encode_count = 0;
|
||||||
|
|
||||||
/* First, pass through the string to see if there's anything to do,
|
/* First pass: inspect the string to see if there's anything to do,
|
||||||
and to calculate the new length. */
|
and to calculate the new length. */
|
||||||
for (p1 = s; *p1; p1++)
|
for (p1 = s; *p1; p1++)
|
||||||
{
|
if (char_needs_escaping (p1))
|
||||||
switch (decide_copy_method (p1))
|
++encode_count;
|
||||||
{
|
|
||||||
case cm_encode:
|
|
||||||
++encode_count;
|
|
||||||
break;
|
|
||||||
case cm_passthrough:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!encode_count)
|
if (!encode_count)
|
||||||
/* The string is good as it is. */
|
/* The string is good as it is. */
|
||||||
@ -391,25 +381,22 @@ reencode_escapes (const char *s)
|
|||||||
newlen = oldlen + 2 * encode_count;
|
newlen = oldlen + 2 * encode_count;
|
||||||
newstr = xmalloc (newlen + 1);
|
newstr = xmalloc (newlen + 1);
|
||||||
|
|
||||||
|
/* Second pass: copy the string to the destination address, encoding
|
||||||
|
chars when needed. */
|
||||||
p1 = s;
|
p1 = s;
|
||||||
p2 = newstr;
|
p2 = newstr;
|
||||||
|
|
||||||
while (*p1)
|
while (*p1)
|
||||||
{
|
if (char_needs_escaping (p1))
|
||||||
switch (decide_copy_method (p1))
|
{
|
||||||
{
|
unsigned char c = *p1++;
|
||||||
case cm_encode:
|
*p2++ = '%';
|
||||||
{
|
*p2++ = XNUM_TO_DIGIT (c >> 4);
|
||||||
unsigned char c = *p1++;
|
*p2++ = XNUM_TO_DIGIT (c & 0xf);
|
||||||
*p2++ = '%';
|
}
|
||||||
*p2++ = XNUM_TO_DIGIT (c >> 4);
|
else
|
||||||
*p2++ = XNUM_TO_DIGIT (c & 0xf);
|
*p2++ = *p1++;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case cm_passthrough:
|
|
||||||
*p2++ = *p1++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p2 = '\0';
|
*p2 = '\0';
|
||||||
assert (p2 - newstr == newlen);
|
assert (p2 - newstr == newlen);
|
||||||
return newstr;
|
return newstr;
|
||||||
|
Loading…
Reference in New Issue
Block a user