From 291d225a504e7b5ab22785fd472a2bc612491cd5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 12 Sep 2023 15:38:02 +0200 Subject: [PATCH] ctype: add ISUNRESERVED() ... and make Curl_isunreserved() use that macro instead of providing a separate funtion for the purpose. Closes #11840 --- lib/curl_ctype.h | 4 ++++ lib/escape.c | 27 --------------------------- lib/escape.h | 4 +++- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/lib/curl_ctype.h b/lib/curl_ctype.h index 1d1d60c28d..c7b370c592 100644 --- a/lib/curl_ctype.h +++ b/lib/curl_ctype.h @@ -43,5 +43,9 @@ #define ISDIGIT(x) (((x) >= '0') && ((x) <= '9')) #define ISBLANK(x) (((x) == ' ') || ((x) == '\t')) #define ISSPACE(x) (ISBLANK(x) || (((x) >= 0xa) && ((x) <= 0x0d))) +#define isurlpuntcs(x) (((x) == '-') || ((x) == '.') || ((x) == '_') || \ + ((x) == '~')) +#define ISUNRESERVED(x) (ISALNUM(x) || isurlpuntcs(x)) + #endif /* HEADER_CURL_CTYPE_H */ diff --git a/lib/escape.c b/lib/escape.c index 56aa2b3988..2fc1d1ee56 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -38,33 +38,6 @@ #include "curl_memory.h" #include "memdebug.h" -/* Portable character check (remember EBCDIC). Do not use isalnum() because - its behavior is altered by the current locale. - See https://datatracker.ietf.org/doc/html/rfc3986#section-2.3 -*/ -bool Curl_isunreserved(unsigned char in) -{ - 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': - case '-': case '.': case '_': case '~': - return TRUE; - default: - break; - } - return FALSE; -} - /* for ABI-compatibility with previous versions */ char *curl_escape(const char *string, int inlength) { diff --git a/lib/escape.h b/lib/escape.h index cdbb712acc..b9fd272f6b 100644 --- a/lib/escape.h +++ b/lib/escape.h @@ -26,7 +26,9 @@ /* Escape and unescape URL encoding in strings. The functions return a new * allocated string or NULL if an error occurred. */ -bool Curl_isunreserved(unsigned char in); +#include "curl_ctype.h" + +#define Curl_isunreserved(x) ISUNRESERVED(x) enum urlreject { REJECT_NADA = 2, -- 2.47.2