]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: replace while(ISBLANK()) loops with Curl_str_passblanks()
authorDaniel Stenberg <daniel@haxx.se>
Thu, 27 Feb 2025 22:26:54 +0000 (23:26 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 3 Mar 2025 09:56:09 +0000 (10:56 +0100)
- replace several ISSPACE() with ISBLANK(), since the former also skips
  CR and LF which in most cases should not occur where this macro is
  used

- after this commit, there is no ISSPACE() user left in libcurl code, but
  unfortunately tool and test code use the macro so it cannot be removed.

Closes #16520

20 files changed:
lib/altsvc.c
lib/content_encoding.c
lib/cookie.c
lib/curl_fnmatch.c
lib/ftplistparser.c
lib/headers.c
lib/hsts.c
lib/http.c
lib/http_aws_sigv4.c
lib/http_digest.c
lib/http_negotiate.c
lib/http_ntlm.c
lib/http_proxy.c
lib/netrc.c
lib/noproxy.c
lib/rtsp.c
lib/strparse.c
lib/strparse.h
lib/strtoofft.c
lib/urlapi.c

index b63cd7beac9af9b8fc9226f94255682d388f087d..d478a874d1f2340175cbac754e307dcd9082b301 100644 (file)
@@ -233,14 +233,10 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
     struct dynbuf buf;
     Curl_dyn_init(&buf, MAX_ALTSVC_LINE);
     while(Curl_get_line(&buf, fp)) {
-      char *lineptr = Curl_dyn_ptr(&buf);
-      while(ISBLANK(*lineptr))
-        lineptr++;
-      if(*lineptr == '#')
-        /* skip commented lines */
-        continue;
-
-      altsvc_add(asi, lineptr);
+      const char *lineptr = Curl_dyn_ptr(&buf);
+      Curl_str_passblanks(&lineptr);
+      if(Curl_str_single(&lineptr, '#'))
+        altsvc_add(asi, lineptr);
     }
     Curl_dyn_free(&buf); /* free the line buffer */
     fclose(fp);
index e39ac3ebadc8809919a8c7824ea3c66c3256ace1..d329a1b56eee3a22b6cbb402c2483b3751792626 100644 (file)
@@ -758,7 +758,7 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
     name = enclist;
 
     for(namelen = 0; *enclist && *enclist != ','; enclist++)
-      if(!ISSPACE(*enclist))
+      if(*enclist > ' ')
         namelen = enclist - name + 1;
 
     if(namelen) {
index 519fcdc4af19c6e53b0cead30171a4a7cf907f82..5a84d7f133fcb17b29856a4bb203f87c1404159d 100644 (file)
@@ -1210,14 +1210,13 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
       struct dynbuf buf;
       Curl_dyn_init(&buf, MAX_COOKIE_LINE);
       while(Curl_get_line(&buf, fp)) {
-        char *lineptr = Curl_dyn_ptr(&buf);
+        const char *lineptr = Curl_dyn_ptr(&buf);
         bool headerline = FALSE;
         if(checkprefix("Set-Cookie:", lineptr)) {
           /* This is a cookie line, get it! */
           lineptr += 11;
           headerline = TRUE;
-          while(ISBLANK(*lineptr))
-            lineptr++;
+          Curl_str_passblanks(&lineptr);
         }
 
         Curl_cookie_add(data, ci, headerline, TRUE, lineptr, NULL, NULL, TRUE);
index ffac8048f67356ef2773d91c10501c55091473a9..58e3f776b90b582f442eec7e6c735d0c4a561263 100644 (file)
@@ -319,7 +319,7 @@ static int loop(const unsigned char *pattern, const unsigned char *string,
         else if(charset[CURLFNM_PRINT])
           found = ISPRINT(*s);
         else if(charset[CURLFNM_SPACE])
-          found = ISSPACE(*s);
+          found = ISBLANK(*s);
         else if(charset[CURLFNM_UPPER])
           found = ISUPPER(*s);
         else if(charset[CURLFNM_LOWER])
index 8ca46998f565c1d245c7d8acdacb86f8a2b98d32..9f60cf931ca4af473b6d7c60d3664671b83d1153 100644 (file)
@@ -443,11 +443,10 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
           else if(c == '\n') {
             mem[parser->item_length - 1] = 0;
             if(!strncmp("total ", mem, 6)) {
-              char *endptr = mem + 6;
+              const char *endptr = mem + 6;
               /* here we can deal with directory size, pass the leading
                  whitespace and then the digits */
-              while(ISBLANK(*endptr))
-                endptr++;
+              Curl_str_passblanks(&endptr);
               while(ISDIGIT(*endptr))
                 endptr++;
               if(*endptr) {
index 411515dfe1fb5041accf8718ab246edcbcf851ca..380e3a2c996848d03548fe81b7af44bd1ccbd851 100644 (file)
@@ -29,6 +29,7 @@
 #include "strcase.h"
 #include "sendf.h"
 #include "headers.h"
+#include "strparse.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -208,14 +209,13 @@ static CURLcode namevalue(char *header, size_t hlen, unsigned int type,
   else
     return CURLE_BAD_FUNCTION_ARGUMENT;
 
-  /* skip all leading space letters */
-  while(ISBLANK(*header))
-    header++;
+  /* skip all leading blank letters */
+  Curl_str_passblanks((const char **)&header);
 
   *value = header;
 
   /* skip all trailing space letters */
-  while((end > header) && ISSPACE(*end))
+  while((end > header) && ISBLANK(*end))
     *end-- = 0; /* nul terminate */
   return CURLE_OK;
 }
@@ -235,7 +235,7 @@ static CURLcode unfold_value(struct Curl_easy *data, const char *value,
   oalloc = olen + offset + 1;
 
   /* skip all trailing space letters */
-  while(vlen && ISSPACE(value[vlen - 1]))
+  while(vlen && ISBLANK(value[vlen - 1]))
     vlen--;
 
   /* save only one leading space */
index 9ea4789e771631897e65351078bb8e6913d4e959..7bad29f83e61e3f0c6beb63f1f2597606dbad978 100644 (file)
@@ -154,8 +154,7 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname,
     return CURLE_OK;
 
   do {
-    while(ISBLANK(*p))
-      p++;
+    Curl_str_passblanks(&p);
     if(strncasecompare("max-age", p, 7)) {
       bool quoted = FALSE;
       int rc;
@@ -164,17 +163,14 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname,
         return CURLE_BAD_FUNCTION_ARGUMENT;
 
       p += 7;
-      while(ISBLANK(*p))
-        p++;
-      if(*p++ != '=')
+      Curl_str_passblanks(&p);
+      if(Curl_str_single(&p, '='))
         return CURLE_BAD_FUNCTION_ARGUMENT;
-      while(ISBLANK(*p))
-        p++;
+      Curl_str_passblanks(&p);
 
-      if(*p == '\"') {
-        p++;
+      if(!Curl_str_single(&p, '\"'))
         quoted = TRUE;
-      }
+
       rc = Curl_str_number(&p, &expires, TIME_T_MAX);
       if(rc == STRE_OVERFLOW)
         expires = CURL_OFF_T_MAX;
@@ -202,8 +198,7 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname,
         p++;
     }
 
-    while(ISBLANK(*p))
-      p++;
+    Curl_str_passblanks(&p);
     if(*p == ';')
       p++;
   } while(*p);
@@ -533,9 +528,9 @@ static CURLcode hsts_load(struct hsts *h, const char *file)
     struct dynbuf buf;
     Curl_dyn_init(&buf, MAX_HSTS_LINE);
     while(Curl_get_line(&buf, fp)) {
-      char *lineptr = Curl_dyn_ptr(&buf);
-      while(ISBLANK(*lineptr))
-        lineptr++;
+      const char *lineptr = Curl_dyn_ptr(&buf);
+      Curl_str_passblanks(&lineptr);
+
       /*
        * Skip empty or commented lines, since we know the line will have a
        * trailing newline from Curl_get_line we can treat length 1 as empty.
index b273059d2d8dc73ad6a22ff37047c5c0f35c31b1..944c35d63c17ce1e00ebc0683ab3939270035722 100644 (file)
@@ -1073,8 +1073,7 @@ CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy,
       auth++;
     else
       break;
-    while(ISBLANK(*auth))
-      auth++;
+    Curl_str_passblanks(&auth);
   }
 #else
   (void) proxy;
@@ -3880,8 +3879,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data,
        */
       const char *p = hd;
 
-      while(ISBLANK(*p))
-        p++;
+      Curl_str_passblanks(&p);
       if(!strncmp(p, "HTTP/", 5)) {
         p += 5;
         switch(*p) {
@@ -3895,7 +3893,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data,
                 k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 +
                   (p[2] - '0');
                 p += 3;
-                if(ISSPACE(*p))
+                if(ISBLANK(*p))
                   fine_statusline = TRUE;
               }
             }
@@ -3915,7 +3913,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data,
             k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 +
               (p[2] - '0');
             p += 3;
-            if(!ISSPACE(*p))
+            if(!ISBLANK(*p))
               break;
             fine_statusline = TRUE;
           }
@@ -4473,8 +4471,7 @@ CURLcode Curl_http_req_to_h2(struct dynhds *h2_headers,
     scheme = Curl_checkheaders(data, STRCONST(HTTP_PSEUDO_SCHEME));
     if(scheme) {
       scheme += sizeof(HTTP_PSEUDO_SCHEME);
-      while(ISBLANK(*scheme))
-        scheme++;
+      Curl_str_passblanks(&scheme);
       infof(data, "set pseudo header %s to %s", HTTP_PSEUDO_SCHEME, scheme);
     }
     else {
index 4ed55f0cee368ebb51b595d2adab4cae05a3cf1c..345ac0910ff8793b0c612ece336f8289844174b2 100644 (file)
@@ -83,7 +83,7 @@ static void trim_headers(struct curl_slist *head)
 {
   struct curl_slist *l;
   for(l = head; l; l = l->next) {
-    char *value; /* to read from */
+    const char *value; /* to read from */
     char *store;
     size_t colon = strcspn(l->data, ":");
     Curl_strntolower(l->data, l->data, colon);
@@ -92,11 +92,10 @@ static void trim_headers(struct curl_slist *head)
     if(!*value)
       continue;
     ++value;
-    store = value;
+    store = (char *)value;
 
     /* skip leading whitespace */
-    while(ISBLANK(*value))
-      value++;
+    Curl_str_passblanks(&value);
 
     while(*value) {
       int space = 0;
@@ -234,7 +233,7 @@ static CURLcode make_headers(struct Curl_easy *data,
       sep = strchr(l->data, ';');
     if(!sep || (*sep == ':' && !*(sep + 1)))
       continue;
-    for(ptr = sep + 1; ISSPACE(*ptr); ++ptr)
+    for(ptr = sep + 1; ISBLANK(*ptr); ++ptr)
       ;
     if(!*ptr && ptr != sep + 1) /* a value of whitespace only */
       continue;
@@ -261,16 +260,15 @@ static CURLcode make_headers(struct Curl_easy *data,
     *date_header = aprintf("%s: %s\r\n", date_hdr_key, timestamp);
   }
   else {
-    char *value;
-    char *endp;
+    const char *value;
+    const char *endp;
     value = strchr(*date_header, ':');
     if(!value) {
       *date_header = NULL;
       goto fail;
     }
     ++value;
-    while(ISBLANK(*value))
-      ++value;
+    Curl_str_passblanks(&value);
     endp = value;
     while(*endp && ISALNUM(*endp))
       ++endp;
@@ -334,14 +332,14 @@ fail:
                                 SHA256_HEX_LENGTH)
 
 /* try to parse a payload hash from the content-sha256 header */
-static char *parse_content_sha_hdr(struct Curl_easy *data,
-                                   const char *provider1,
-                                   size_t plen,
-                                   size_t *value_len)
+static const char *parse_content_sha_hdr(struct Curl_easy *data,
+                                         const char *provider1,
+                                         size_t plen,
+                                         size_t *value_len)
 {
   char key[CONTENT_SHA256_KEY_LEN];
   size_t key_len;
-  char *value;
+  const char *value;
   size_t len;
 
   key_len = msnprintf(key, sizeof(key), "x-%.*s-content-sha256",
@@ -356,8 +354,7 @@ static char *parse_content_sha_hdr(struct Curl_easy *data,
     return NULL;
   ++value;
 
-  while(ISBLANK(*value))
-    ++value;
+  Curl_str_passblanks(&value);
 
   len = strlen(value);
   while(len > 0 && ISBLANK(value[len-1]))
@@ -593,7 +590,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data, bool proxy)
   char *date_header = NULL;
   Curl_HttpReq httpreq;
   const char *method = NULL;
-  char *payload_hash = NULL;
+  const char *payload_hash = NULL;
   size_t payload_hash_len = 0;
   unsigned char sha_hash[CURL_SHA256_DIGEST_LENGTH];
   char sha_hex[SHA256_HEX_LENGTH];
index 3c81640f20d5d55318c3dcc3a0d6fa3a3b1d069c..6b27a19a7e7cd2da3d46918ec5f3523af3a7cde8 100644 (file)
@@ -30,6 +30,7 @@
 #include "strcase.h"
 #include "vauth/vauth.h"
 #include "http_digest.h"
+#include "strparse.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -62,8 +63,7 @@ CURLcode Curl_input_digest(struct Curl_easy *data,
     return CURLE_BAD_CONTENT_ENCODING;
 
   header += strlen("Digest");
-  while(ISBLANK(*header))
-    header++;
+  Curl_str_passblanks(&header);
 
   return Curl_auth_decode_digest_http_message(header, digest);
 }
index b686b8ebc6091f71e8d169a97092ae3db3791216..dd90a4e137df4ea4e7d8ee6d3d41d74840fb4b54 100644 (file)
@@ -32,6 +32,7 @@
 #include "http_negotiate.h"
 #include "vauth/vauth.h"
 #include "vtls/vtls.h"
+#include "strparse.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -86,8 +87,7 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn,
 
   /* Obtain the input token, if any */
   header += strlen("Negotiate");
-  while(ISBLANK(*header))
-    header++;
+  Curl_str_passblanks(&header);
 
   len = strlen(header);
   neg_ctx->havenegdata = len != 0;
index 2eee92742a8a3e9618f60be50212b77036e40247..a2d342a7a01a9e0d22d26b443928433bb9ecd243 100644 (file)
@@ -41,6 +41,7 @@
 #include "curl_base64.h"
 #include "vauth/vauth.h"
 #include "url.h"
+#include "strparse.h"
 
 /* SSL backend-specific #if branches in this file must be kept in the order
    documented in curl_ntlm_core. */
@@ -70,9 +71,7 @@ CURLcode Curl_input_ntlm(struct Curl_easy *data,
   if(checkprefix("NTLM", header)) {
     header += strlen("NTLM");
 
-    while(ISSPACE(*header))
-      header++;
-
+    Curl_str_passblanks(&header);
     if(*header) {
       unsigned char *hdr;
       size_t hdrlen;
index 0ccb826edb4fab86c9c78dc0c750f777d9b09809..0cacf4cef3e652985f41784f7ecc856393f90487 100644 (file)
@@ -43,6 +43,7 @@
 #include "transfer.h"
 #include "multiif.h"
 #include "vauth/vauth.h"
+#include "strparse.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -60,7 +61,7 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data,
                                   struct dynhds *hds)
 {
   struct connectdata *conn = data->conn;
-  char *ptr;
+  const char *ptr;
   struct curl_slist *h[2];
   struct curl_slist *headers;
   int numlists = 1; /* by default */
@@ -108,8 +109,7 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data,
         name = headers->data;
         namelen = ptr - headers->data;
         ptr++; /* pass the colon */
-        while(ISSPACE(*ptr))
-          ptr++;
+        Curl_str_passblanks(&ptr);
         if(*ptr) {
           value = ptr;
           valuelen = strlen(value);
@@ -131,8 +131,7 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data,
         name = headers->data;
         namelen = ptr - headers->data;
         ptr++; /* pass the semicolon */
-        while(ISSPACE(*ptr))
-          ptr++;
+        Curl_str_passblanks(&ptr);
         if(!*ptr) {
           /* quirk #2, send an empty header */
           value = "";
index 00aca78ece9bbe340e4d74f02b5bdb9fb35a27c6..83c6f42ac28feb6176dca7024efc391dac004c96 100644 (file)
@@ -39,6 +39,7 @@
 #include "netrc.h"
 #include "strcase.h"
 #include "curl_get_line.h"
+#include "strparse.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -85,8 +86,7 @@ static NETRCcode file2memory(const char *filename, struct dynbuf *filebuf)
       CURLcode result;
       const char *line = Curl_dyn_ptr(&linebuf);
       /* skip comments on load */
-      while(ISBLANK(*line))
-        line++;
+      Curl_str_passblanks(&line);
       if(*line == '#')
         continue;
       result = Curl_dyn_add(filebuf, line);
@@ -138,13 +138,12 @@ static NETRCcode parsenetrc(struct store_netrc *store,
   netrcbuffer = Curl_dyn_ptr(filebuf);
 
   while(!done) {
-    char *tok = netrcbuffer;
+    const char *tok = netrcbuffer;
     while(tok && !done) {
-      char *tok_end;
+      const char *tok_end;
       bool quoted;
       Curl_dyn_reset(&token);
-      while(ISBLANK(*tok))
-        tok++;
+      Curl_str_passblanks(&tok);
       /* tok is first non-space letter */
       if(state == MACDEF) {
         if((*tok == '\n') || (*tok == '\r'))
@@ -162,7 +161,7 @@ static NETRCcode parsenetrc(struct store_netrc *store,
       if(!quoted) {
         size_t len = 0;
         CURLcode result;
-        while(!ISSPACE(*tok_end)) {
+        while(*tok_end > ' ') {
           tok_end++;
           len++;
         }
index 23dd46ba747d85a0c882aa47d2c9afe0fd5d03ca..d8cf1ddd74d17431a0c062b4acbac9d54e83feac 100644 (file)
@@ -29,6 +29,7 @@
 #include "inet_pton.h"
 #include "strcase.h"
 #include "noproxy.h"
+#include "strparse.h"
 
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
@@ -177,8 +178,7 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy)
       bool match = FALSE;
 
       /* pass blanks */
-      while(ISBLANK(*p))
-        p++;
+      Curl_str_passblanks(&p);
 
       token = p;
       /* pass over the pattern */
@@ -247,8 +247,7 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy)
           return TRUE;
       } /* if(tokenlen) */
       /* pass blanks after pattern */
-      while(ISBLANK(*p))
-        p++;
+      Curl_str_passblanks(&p);
       /* if not a comma, this ends the loop */
       if(*p != ',')
         break;
index 7ff7274cb9cf9bb6a00de96b9ac1204f3f566f9b..5ce8b001b2cc16ce679ad614415cac8e1a2b31f7 100644 (file)
@@ -929,8 +929,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header)
     curl_off_t CSeq = 0;
     struct RTSP *rtsp = data->req.p.rtsp;
     const char *p = &header[5];
-    while(ISBLANK(*p))
-      p++;
+    Curl_str_passblanks(&p);
     if(Curl_str_number(&p, &CSeq, LONG_MAX)) {
       failf(data, "Unable to read the CSeq header: [%s]", header);
       return CURLE_RTSP_CSEQ_ERROR;
@@ -944,8 +943,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header)
 
     /* Find the first non-space letter */
     start = header + 8;
-    while(ISBLANK(*start))
-      start++;
+    Curl_str_passblanks(&start);
 
     if(!*start) {
       failf(data, "Got a blank Session ID");
@@ -959,7 +957,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header)
      * gstreamer does url-encoded session ID's not covered by the standard.
      */
     end = start;
-    while(*end && *end != ';' && !ISSPACE(*end))
+    while((*end > ' ') && (*end != ';'))
       end++;
     idlen = end - start;
 
@@ -1003,8 +1001,7 @@ CURLcode rtsp_parse_transport(struct Curl_easy *data, const char *transport)
   const char *start, *end;
   start = transport;
   while(start && *start) {
-    while(ISBLANK(*start) )
-      start++;
+    Curl_str_passblanks(&start);
     end = strchr(start, ';');
     if(checkprefix("interleaved=", start)) {
       curl_off_t chan1, chan2, chan;
index a78c38490641783e6395085f1403051877c94d30..db31cd71254a427e317954c1c8aaa8a30eaef2a8 100644 (file)
@@ -283,3 +283,10 @@ void Curl_str_trimblanks(struct Curl_str *out)
   while(out->len && ISBLANK(out->str[out->len - 1]))
     out->len--;
 }
+
+/* increase the pointer until it has moved over all blanks */
+void Curl_str_passblanks(const char **linep)
+{
+  while(ISBLANK(**linep))
+    (*linep)++; /* move over it */
+}
index e9109c55c2117e17e0de2a60b706ca0681c962c9..8b4d1b68e944abb3c7d22ae4b50f5d5fbfd963b4 100644 (file)
@@ -97,5 +97,6 @@ int Curl_str_nudge(struct Curl_str *str, size_t num);
 
 int Curl_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);
 void Curl_str_trimblanks(struct Curl_str *out);
+void Curl_str_passblanks(const char **linep);
 
 #endif /* HEADER_CURL_STRPARSE_H */
index f347e2b6fe8f760ccb9d7180c59d55071123ae52..6da60cd5e525414e9d712132a38ee137498c60ca 100644 (file)
@@ -39,9 +39,7 @@ CURLofft curlx_strtoofft(const char *str, char **endp, int base,
   *num = 0; /* clear by default */
   DEBUGASSERT((base == 10) || (base == 16));
 
-  while(ISBLANK(*str))
-    str++;
-
+  Curl_str_passblanks(&str);
   rc = base == 10 ?
     Curl_str_number(&str, &number, CURL_OFF_T_MAX) :
     Curl_str_hex(&str, &number, CURL_OFF_T_MAX);
index 060ccec15195b7a5b024b41c80dd756671eb03f7..06adda112768ec37d7567bdac31550ee78e1bbe0 100644 (file)
@@ -128,10 +128,6 @@ static const char *find_host_sep(const char *url)
 /* convert CURLcode to CURLUcode */
 #define cc2cu(x) ((x) == CURLE_TOO_LARGE ? CURLUE_TOO_LARGE :   \
                   CURLUE_OUT_OF_MEMORY)
-/*
- * Decide whether a character in a URL must be escaped.
- */
-#define urlchar_needs_escaping(c) (!(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c)))
 
 static const char hexdigits[] = "0123456789abcdef";
 /* urlencode_str() writes data into an output dynbuf and URL-encodes the
@@ -167,7 +163,7 @@ static CURLUcode urlencode_str(struct dynbuf *o, const char *url,
       else
         result = Curl_dyn_addn(o, "+", 1);
     }
-    else if(urlchar_needs_escaping(*iptr)) {
+    else if((*iptr < ' ') || (*iptr >= 0x7f)) {
       char out[3]={'%'};
       out[1] = hexdigits[*iptr >> 4];
       out[2] = hexdigits[*iptr & 0xf];