diff options
author | des <des@FreeBSD.org> | 2000-10-21 14:58:18 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-10-21 14:58:18 +0000 |
commit | cbb8cbedb3f4e6af0fd2457326f543adb2638fc8 (patch) | |
tree | 450ce3f07632942c30663e30859bc802cd02173b /lib/libfetch | |
parent | 1a2146d59f7d2942dd0de314ad96ccdfcb8c7636 (diff) | |
download | FreeBSD-src-cbb8cbedb3f4e6af0fd2457326f543adb2638fc8.zip FreeBSD-src-cbb8cbedb3f4e6af0fd2457326f543adb2638fc8.tar.gz |
If the scheme is HTTP or HTTPS, percent-escape whitespace in the document
part.
Submitted by: green
Diffstat (limited to 'lib/libfetch')
-rw-r--r-- | lib/libfetch/fetch.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c index e79dba8..b814336 100644 --- a/lib/libfetch/fetch.c +++ b/lib/libfetch/fetch.c @@ -367,7 +367,27 @@ nohost: 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; } |