X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/5b708e0cac7e269355f5b38480ad0256e5831a0d..04024c2cafab56ea76a9a2b35097584d6db98c06:/lib/t-cgi.c diff --git a/lib/t-cgi.c b/lib/t-cgi.c index a055c67..de44fcb 100644 --- a/lib/t-cgi.c +++ b/lib/t-cgi.c @@ -24,7 +24,10 @@ static void input_from(const char *s) { 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); @@ -44,6 +47,7 @@ static void test_cgi(void) { 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(); @@ -51,8 +55,60 @@ static void test_cgi(void) { 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>"); check_string(cgi_sgmlquote("\"&\""), ""&"");