int ret;
/* We must start with a boundary string */
- if(!isboundary(s, boundary, bl))
+ if(!isboundary(s, boundary, bl)) {
+ error(0, "mime_multipart: first line is not the boundary string");
return -1;
+ }
/* Keep going until we hit a final boundary */
while(!isfinal(s, boundary, bl)) {
s = strstr(s, "\r\n") + 2;
start = s;
while(!isboundary(s, boundary, bl)) {
- if(!(e = strstr(s, "\r\n")))
+ if(!(e = strstr(s, "\r\n"))) {
+ error(0, "mime_multipart: line does not end CRLF");
return -1;
+ }
s = e + 2;
}
if((ret = callback(xstrndup(start,
check_string(cgi_get("c"), "x~y");
setenv("REQUEST_METHOD", "POST", 1);
+ setenv("CONTENT_TYPE", "application/x-www-form-urlencoded", 1);
unsetenv("QUERY_STRING");
input_from("foo=xbar&a=xb+c&c=xx%7ey");
cgi_init();
check_string(cgi_get("a"), "xb c");
check_string(cgi_get("c"), "xx~y");
- /* TODO multipart/form-data */
+ /* This input string generated by Firefox 2.0.0.14 */
+ input_from("-----------------------------16128946562344073111198667379\r\n"
+ "Content-Disposition: form-data; name=\"input1\"\r\n"
+ "\r\n"
+ "normal input\r\n"
+ "-----------------------------16128946562344073111198667379\r\n"
+ "Content-Disposition: form-data; name=\"input2\"\r\n"
+ "\r\n"
+ "with pound sign: \xC2\xA3\r\n"
+ "-----------------------------16128946562344073111198667379\r\n"
+ "Content-Disposition: form-data; name=\"input3\"\r\n"
+ "\r\n"
+ "hidden input\r\n"
+ "-----------------------------16128946562344073111198667379\r\n"
+ "Content-Disposition: form-data; name=\"submit\"\r\n"
+ "\r\n"
+ "Submit Query\r\n"
+ "-----------------------------16128946562344073111198667379--\r\n");
+ setenv("CONTENT_TYPE", "multipart/form-data; boundary=---------------------------16128946562344073111198667379", 1);
+ unsetenv("QUERY_STRING");
+ cgi_init();
+ check_string(cgi_get("input1"), "normal input");
+ check_string(cgi_get("input2"), "with pound sign: \xC2\xA3");
+ check_string(cgi_get("input3"), "hidden input");
+ check_string(cgi_get("submit"), "Submit Query");
+ input_from("-----------------------------33919340914020259251659146591\r\n"
+ "Content-Disposition: form-data; name=\"text\"\r\n"
+ "\r\n"
+ "Text with\r\n"
+ "multiple lines\r\n"
+ "and trailing spaces \r\n"
+ "---and leading dashes\r\n"
+ "and pound sign \xC2\xA3\r\n"
+ "\r\n"
+ "-----------------------------33919340914020259251659146591\r\n"
+ "Content-Disposition: form-data; name=\"empty\"\r\n"
+ "\r\n"
+ "\r\n"
+ "-----------------------------33919340914020259251659146591\r\n"
+ "Content-Disposition: form-data; name=\"submit\"\r\n"
+ "\r\n"
+ "Submit Query\r\n"
+ "-----------------------------33919340914020259251659146591--\r\n");
+ setenv("CONTENT_TYPE", "multipart/form-data; boundary=---------------------------33919340914020259251659146591", 1);
+ cgi_init();
+ check_string(cgi_get("text"), ("Text with\r\n"
+ "multiple lines\r\n"
+ "and trailing spaces \r\n"
+ "---and leading dashes\r\n"
+ "and pound sign \xC2\xA3\r\n"
+ ""));
+ check_string(cgi_get("empty"), "");
+
check_string(cgi_sgmlquote("foobar"), "foobar");
check_string(cgi_sgmlquote("<wibble>"), "<wibble>");
check_string(cgi_sgmlquote("\"&\""), ""&"");