*/
static bool urlchar_needs_escaping(int c)
{
- return !(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c));
+ return !(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c));
}
/*
}
/* scan for byte values < 31 or 127 */
-static CURLUcode junkscan(const char *part)
+static bool junkscan(const char *part, unsigned int flags)
{
if(part) {
static const char badbytes[]={
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x7f,
- 0x00 /* null-terminate */
+ 0x7f, 0x00 /* null-terminate */
};
size_t n = strlen(part);
size_t nfine = strcspn(part, badbytes);
if(nfine != n)
/* since we don't know which part is scanned, return a generic error
code */
- return CURLUE_MALFORMED_INPUT;
+ return TRUE;
+ if(!(flags & CURLU_ALLOW_SPACE) && strchr(part, ' '))
+ return TRUE;
}
- return CURLUE_OK;
+ return FALSE;
}
static CURLUcode hostname_check(struct Curl_URL *u, char *hostname)
!(flags & CURLU_NON_SUPPORT_SCHEME))
return CURLUE_UNSUPPORTED_SCHEME;
- if(junkscan(schemep))
+ if(junkscan(schemep, flags))
return CURLUE_MALFORMED_INPUT;
-
}
else {
/* no scheme! */
}
}
- if(junkscan(path))
+ if(junkscan(path, flags))
return CURLUE_MALFORMED_INPUT;
if((flags & CURLU_URLENCODE) && path[0]) {
/*
* Parse the login details and strip them out of the host name.
*/
- if(junkscan(hostname))
+ if(junkscan(hostname, flags))
return CURLUE_MALFORMED_INPUT;
result = parse_hostname_login(u, &hostname, flags);
};
static struct testcase get_parts_list[] ={
+ {"https://user:password@example.net/get?this=and what", "",
+ CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
+ {"https://user:password@example.net/ge t?this=and-what", "",
+ CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
+ {"https://user:pass word@example.net/get?this=and-what", "",
+ CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
+ {"https://u ser:password@example.net/get?this=and-what", "",
+ CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
+ /* no space allowed in scheme */
+ {"htt ps://user:password@example.net/get?this=and-what", "",
+ CURLU_NON_SUPPORT_SCHEME|CURLU_ALLOW_SPACE, 0, CURLUE_MALFORMED_INPUT},
+ {"https://user:password@example.net/get?this=and what",
+ "https | user | password | [13] | example.net | [15] | /get | "
+ "this=and what | [17]",
+ CURLU_ALLOW_SPACE, 0, CURLUE_OK},
+ {"https://user:password@example.net/ge t?this=and-what",
+ "https | user | password | [13] | example.net | [15] | /ge t | "
+ "this=and-what | [17]",
+ CURLU_ALLOW_SPACE, 0, CURLUE_OK},
+ {"https://user:pass word@example.net/get?this=and-what",
+ "https | user | pass word | [13] | example.net | [15] | /get | "
+ "this=and-what | [17]",
+ CURLU_ALLOW_SPACE, 0, CURLUE_OK},
+ {"https://u ser:password@example.net/get?this=and-what",
+ "https | u ser | password | [13] | example.net | [15] | /get | "
+ "this=and-what | [17]",
+ CURLU_ALLOW_SPACE, 0, CURLUE_OK},
+ {"https://user:password@example.net/ge t?this=and-what",
+ "https | user | password | [13] | example.net | [15] | /ge%20t | "
+ "this=and-what | [17]",
+ CURLU_ALLOW_SPACE | CURLU_URLENCODE, 0, CURLUE_OK},
{"[::1]",
"http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
CURLU_GUESS_SCHEME, 0, CURLUE_OK },
{"https://127abc.com",
"https | [11] | [12] | [13] | 127abc.com | [15] | / | [16] | [17]",
CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
- {"https:// example.com?check",
- "",
+ {"https:// example.com?check", "",
CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
- {"https://e x a m p l e.com?check",
- "",
+ {"https://e x a m p l e.com?check", "",
CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
{"https://example.com?check",
"https | [11] | [12] | [13] | example.com | [15] | / | check | [17]",
CURLU_GUESS_SCHEME, 0, CURLUE_OK},
{"HTTP://test/", "http://test/", 0, 0, CURLUE_OK},
{"http://HO0_-st..~./", "http://HO0_-st..~./", 0, 0, CURLUE_OK},
- {"http:/@example.com: 123/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
- {"http:/@example.com:123 /", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
+ {"http:/@example.com: 123/", "", 0, 0, CURLUE_MALFORMED_INPUT},
+ {"http:/@example.com:123 /", "", 0, 0, CURLUE_MALFORMED_INPUT},
{"http:/@example.com:123a/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
{"http://host/file\r", "", 0, 0, CURLUE_MALFORMED_INPUT},
{"http://host/file\n\x03", "", 0, 0, CURLUE_MALFORMED_INPUT},