From d16be832996ef8a2844df3f7c91afe58cc7a46fb Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Mon, 5 May 2008 10:44:06 +0100 Subject: [PATCH] cgi.c multipart/form-data testing. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/mime.c | 8 ++++++-- lib/t-cgi.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/lib/mime.c b/lib/mime.c index da41426..5db7585 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -381,15 +381,19 @@ int mime_multipart(const char *s, 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, diff --git a/lib/t-cgi.c b/lib/t-cgi.c index a055c67..a3b9f37 100644 --- a/lib/t-cgi.c +++ b/lib/t-cgi.c @@ -44,6 +44,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 +52,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("\"&\""), ""&""); -- [mdw]