Skip to content

Commit b596c3b

Browse files
author
grothoff
committed
testcase for #2733
git-svn-id: https://gnunet.org/svn/libmicrohttpd@25971 140774ce-b5e7-0310-ab8b-a85725594a96
1 parent d9c8c82 commit b596c3b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/daemon/postprocessor_test.c

+44
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ const char *want[] = {
6060
"pics", "file2.gif", "image/gif", "binary", "filedata2",
6161
#define FORM_NESTED_END (FORM_NESTED_START + 15)
6262
NULL, NULL, NULL, NULL, NULL,
63+
#define URL_EMPTY_VALUE_DATA "key1=value1&key2="
64+
#define URL_EMPTY_VALUE_START (FORM_NESTED_END + 5)
65+
"key1", NULL, NULL, NULL, "value1",
66+
"key2", NULL, NULL, NULL, NULL,
67+
#define URL_EMPTY_VALUE_END (URL_EMPTY_VALUE_START + 10)
68+
NULL, NULL, NULL, NULL, NULL
6369
};
6470

6571
static int
@@ -212,6 +218,43 @@ test_nested_multipart ()
212218
return 0;
213219
}
214220

221+
222+
static int
223+
test_empty_value ()
224+
{
225+
struct MHD_Connection connection;
226+
struct MHD_HTTP_Header header;
227+
struct MHD_PostProcessor *pp;
228+
unsigned int want_off = URL_EMPTY_VALUE_START;
229+
int i;
230+
int delta;
231+
size_t size;
232+
233+
memset (&connection, 0, sizeof (struct MHD_Connection));
234+
memset (&header, 0, sizeof (struct MHD_HTTP_Header));
235+
connection.headers_received = &header;
236+
header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
237+
header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
238+
header.kind = MHD_HEADER_KIND;
239+
pp = MHD_create_post_processor (&connection,
240+
1024, &value_checker, &want_off);
241+
i = 0;
242+
size = strlen (URL_EMPTY_VALUE_DATA);
243+
while (i < size)
244+
{
245+
delta = 1 + RANDOM () % (size - i);
246+
MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta);
247+
i += delta;
248+
}
249+
MHD_destroy_post_processor (pp);
250+
if (want_off != URL_EMPTY_VALUE_END)
251+
return 8;
252+
return 0;
253+
}
254+
255+
256+
257+
215258
int
216259
main (int argc, char *const *argv)
217260
{
@@ -220,6 +263,7 @@ main (int argc, char *const *argv)
220263
errorCount += test_urlencoding ();
221264
errorCount += test_multipart ();
222265
errorCount += test_nested_multipart ();
266+
errorCount += test_empty_value ();
223267
if (errorCount != 0)
224268
fprintf (stderr, "Error (code: %u)\n", errorCount);
225269
return errorCount != 0; /* 0 == pass */

0 commit comments

Comments
 (0)