If the scheme is HTTP or HTTPS, percent-escape whitespace in the document

part.

Submitted by:	green
This commit is contained in:
Dag-Erling Smørgrav 2000-10-21 14:58:18 +00:00
parent f3581390d2
commit 23fe6d7a4c

View File

@ -367,7 +367,27 @@ fetchParseURL(char *URL)
if (!*p)
p = "/";
if ((u->doc = strdup(p)) == NULL) {
if (strcmp(u->scheme, "http") == 0 || strcmp(u->scheme, "https") == 0) {
const char hexnums[] = "0123456789abcdef";
char *doc;
/* Perform %hh encoding of white space. */
if ((doc = u->doc = malloc(strlen(p) * 3 + 1)) == NULL) {
_fetch_syserr();
goto ouch;
}
while (*p != '\0') {
if (!isspace(*p)) {
*doc++ = *p++;
} else {
*doc++ = '%';
*doc++ = hexnums[((unsigned int)*p) >> 4];
*doc++ = hexnums[((unsigned int)*p) & 0xf];
p++;
}
}
*doc = '\0';
} else if ((u->doc = strdup(p)) == NULL) {
_fetch_syserr();
goto ouch;
}