FILE *fp = tmpfile();
char buffer[64];
- if(fputs(s, fp) < 0 || fflush(fp) < 0)
+ if(fputs(s, fp) < 0
+ || fputs("wibble wibble\r\nspong", fp) < 0 /* ensure CONTENT_LENGTH
+ * honored */
+ || fflush(fp) < 0)
fatal(errno, "writing to temporary file");
rewind(fp);
xdup2(fileno(fp), 0);
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("\"&\""), ""&"");