MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / percentDecode

Function percentDecode

src/redis-cli.c:197–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195#define decodeHex(h, l) ((decodeHexChar(h) << 4) + decodeHexChar(l))
196
197static sds percentDecode(const char *pe, size_t len) {
198 const char *end = pe + len;
199 sds ret = sdsempty();
200 const char *curr = pe;
201
202 while (curr < end) {
203 if (*curr == '%') {
204 if ((end - curr) < 2) {
205 fprintf(stderr, "Incomplete URI encoding\n");
206 exit(1);
207 }
208
209 char h = tolower(*(++curr));
210 char l = tolower(*(++curr));
211 if (!isHexChar(h) || !isHexChar(l)) {
212 fprintf(stderr, "Illegal character in URI encoding\n");
213 exit(1);
214 }
215 char c = decodeHex(h, l);
216 ret = sdscatlen(ret, &c, 1);
217 curr++;
218 } else {
219 ret = sdscatlen(ret, curr++, 1);
220 }
221 }
222
223 return ret;
224}
225
226/* Parse a URI and extract the server connection information.
227 * URI scheme is based on the the provisional specification[1] excluding support

Callers 1

parseRedisUriFunction · 0.85

Calls 2

sdsemptyFunction · 0.85
sdscatlenFunction · 0.85

Tested by

no test coverage detected