diff options
author | Daniel Stenberg <daniel@haxx.se> | 2007-08-04 20:47:59 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2007-08-04 20:47:59 +0000 |
commit | 1926f4573d43f35f33b524d120e847ea819cc7c7 (patch) | |
tree | 9c19380b002d623c94747daee0edb941542451cc | |
parent | 7fe65aaf5bda5f48eebcc3f694485b2bc6b49d6c (diff) |
Patrick Monnerat fixed curl_easy_escape() and curlx_strtoll() to work on
non-ASCII systems.
-rw-r--r-- | CHANGES | 10 | ||||
-rw-r--r-- | lib/escape.c | 29 | ||||
-rw-r--r-- | lib/strtoofft.c | 27 |
3 files changed, 59 insertions, 7 deletions
@@ -6,6 +6,16 @@ Changelog +Daniel S (4 August 2007) +- Patrick Monnerat fixed curl_easy_escape() and curlx_strtoll() to work on + non-ASCII systems. + +Daniel S (3 August 2007) +- I cut out support for libssh2 versions older than 0.16 to make our code a + lot simpler, and to avoid getting trouble with the LIBSSH2_APINO define + that 1) didn't work properly since it was >32 bits and 2) is removed in + libssh2 0.16... + Daniel S (2 August 2007) - Scott Cantor filed bug report #1766320 (http://curl.haxx.se/bug/view.cgi?id=1766320) pointing out that the libcurl diff --git a/lib/escape.c b/lib/escape.c index 9552b0f31..06ac04d71 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -75,9 +75,27 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength) length = alloc-1; while(length--) { in = *string; - if(!(in >= 'a' && in <= 'z') && - !(in >= 'A' && in <= 'Z') && - !(in >= '0' && in <= '9')) { + + /* Portable character check (remember EBCDIC). Do not use isalnum() because + its behavior is altered by the current locale. */ + + switch (in) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': + /* just copy this */ + ns[strindex++]=in; + break; + default: /* encode it */ newlen += 2; /* the size grows with two, since this'll become a %XX */ if(newlen > alloc) { @@ -105,10 +123,7 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength) snprintf(&ns[strindex], 4, "%%%02X", in); strindex+=3; - } - else { - /* just copy this */ - ns[strindex++]=in; + break; } string++; } diff --git a/lib/strtoofft.c b/lib/strtoofft.c index 5314fa403..043ff4d9b 100644 --- a/lib/strtoofft.c +++ b/lib/strtoofft.c @@ -37,6 +37,18 @@ #include <ctype.h> #include <errno.h> +/* Range tests can be used for alphanum decoding if characters are consecutive, + like in ASCII. Else an array is scanned. Determine this condition now. */ + +#if ('9' - '0') != 9 || ('Z' - 'A') != 25 || ('z' - 'a') != 25 +#include <string.h> + +#define NO_RANGE_TEST + +static const char valchars[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +#endif + static int get_char(char c, int base); /** @@ -145,6 +157,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base) */ static int get_char(char c, int base) { +#ifndef NO_RANGE_TEST int value = -1; if (c <= '9' && c >= '0') { value = c - '0'; @@ -155,6 +168,20 @@ static int get_char(char c, int base) else if (c <= 'z' && c >= 'a') { value = c - 'a' + 10; } +#else + const char * cp; + int value; + + cp = memchr(valchars, c, 10 + 26 + 26); + + if (!cp) + return -1; + + value = cp - valchars; + + if (value >= 10 + 26) + value -= 26; /* Lowercase. */ +#endif if (value >= base) { value = -1; |