View | Details | Raw Unified | Return to bug 262283
Collapse All | Expand All

(-)b/lib/libfetch/fetch.c (-1 / +12 lines)
Lines 37-42 __FBSDID("$FreeBSD$"); Link Here
37
37
38
#include <errno.h>
38
#include <errno.h>
39
#include <ctype.h>
39
#include <ctype.h>
40
#include <stdbool.h>
40
#include <stdio.h>
41
#include <stdio.h>
41
#include <stdlib.h>
42
#include <stdlib.h>
42
#include <string.h>
43
#include <string.h>
Lines 443-457 fetchParseURL(const char *URL) Link Here
443
	if (strcmp(u->scheme, SCHEME_HTTP) == 0 ||
444
	if (strcmp(u->scheme, SCHEME_HTTP) == 0 ||
444
	    strcmp(u->scheme, SCHEME_HTTPS) == 0) {
445
	    strcmp(u->scheme, SCHEME_HTTPS) == 0) {
445
		const char hexnums[] = "0123456789abcdef";
446
		const char hexnums[] = "0123456789abcdef";
447
		bool in_query_string = false;
446
448
447
		/* percent-escape whitespace. */
449
		/* percent-escape whitespace. */
450
		/* Some servers do not handle '+' properly. In the path it must be
451
		 * literal. In the query string it can be an encoded space.
452
		 * Percent-escape the '+' in the path to be unambiguous to the server.
453
		 * https://www.w3.org/Addressing/URL/4_URI_Recommentations.html
454
		 * https://forums.aws.amazon.com/thread.jspa?threadID=55746
455
		 */
448
		if ((doc = malloc(strlen(p) * 3 + 1)) == NULL) {
456
		if ((doc = malloc(strlen(p) * 3 + 1)) == NULL) {
449
			fetch_syserr();
457
			fetch_syserr();
450
			goto ouch;
458
			goto ouch;
451
		}
459
		}
452
		u->doc = doc;
460
		u->doc = doc;
453
		while (*p != '\0') {
461
		while (*p != '\0') {
454
			if (!isspace((unsigned char)*p)) {
462
			if (*p == '?') {
463
				in_query_string = true;
464
			}
465
			if (!isspace((unsigned char)*p) && (in_query_string || *p != '+')) {
455
				*doc++ = *p++;
466
				*doc++ = *p++;
456
			} else {
467
			} else {
457
				*doc++ = '%';
468
				*doc++ = '%';

Return to bug 262283