From: Wilfried Göesgens Date: Sun, 8 Nov 2009 14:46:23 +0000 (+0000) Subject: * this way its fastest: range check whats allowed and mask the rest. X-Git-Tag: v7.86~651 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=af2060dc64c6b35b532109aefad3b53a51bdcc8b;p=citadel.git * this way its fastest: range check whats allowed and mask the rest. --- diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 1573ee979..f560b99c5 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -757,10 +757,8 @@ void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) { const char *pch, *pche; char *pt, *pte; - int b, c, len; - const char ec[] = " +#&;`'|*?-~<>^()[]{}/$\"\\"; - int eclen = sizeof(ec) -1; - + int len; + if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) ) return; if (PlainIn != NULL) { @@ -786,27 +784,25 @@ void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) pte = OutBuf->buf + OutBuf->BufSize - 4; /**< we max append 3 chars at once plus the \0 */ pt = OutBuf->buf + OutBuf->BufUsed; } - - c = 0; - for (b = 0; b < eclen; ++b) { - if (*pch == ec[b]) { - c = 1; - b += eclen; - } - } - if (c == 1) { + + if((*pch >= 'a' && *pch <= 'z') || + (*pch >= '@' && *pch <= 'Z') || /* @ A-Z */ + (*pch >= '0' && *pch <= ':') || /* 0-9 : */ + (*pch == '!') || (*pch == '_') || + (*pch == ',') || (*pch == '.') || + (*pch == ',')) + { + *(pt++) = *(pch++); + OutBuf->BufUsed++; + } + else { *pt = '%'; - *(pt + 1) = HexList[(unsigned char)*pch][0]; *(pt + 2) = HexList[(unsigned char)*pch][1]; pt += 3; OutBuf->BufUsed += 3; pch ++; } - else { - *(pt++) = *(pch++); - OutBuf->BufUsed++; - } } *pt = '\0'; }