From 23fe6d7a4c20187171a175e7e5202fad6e69bafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sat, 21 Oct 2000 14:58:18 +0000 Subject: [PATCH] If the scheme is HTTP or HTTPS, percent-escape whitespace in the document part. Submitted by: green --- lib/libfetch/fetch.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c index e79dba83b0ab..b814336285b3 100644 --- a/lib/libfetch/fetch.c +++ b/lib/libfetch/fetch.c @@ -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; }