Index: lib/escape.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/escape.c,v
retrieving revision 1.38
diff -u -r1.38 escape.c
--- lib/escape.c	17 Oct 2006 21:32:56 -0000	1.38
+++ lib/escape.c	17 Jul 2007 20:08:30 -0000
@@ -75,9 +75,27 @@
   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 @@
       snprintf(&ns[strindex], 4, "%%%02X", in);
 
       strindex+=3;
-    }
-    else {
-      /* just copy this */
-      ns[strindex++]=in;
+      break;
     }
     string++;
   }
Index: lib/strtoofft.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/strtoofft.c,v
retrieving revision 1.11
diff -u -r1.11 strtoofft.c
--- lib/strtoofft.c	16 Feb 2007 18:19:36 -0000	1.11
+++ lib/strtoofft.c	3 Aug 2007 12:13:05 -0000
@@ -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 @@
  */
 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 @@
   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;
