aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-10-15 14:44:53 +0200
committerjcid <devnull@localhost>2008-10-15 14:44:53 +0200
commit321e48930d7de527bfa73367f3e54a915039d120 (patch)
tree9deb933edd8f72bbbc43db0b41186e6fd2f78372 /src
parent1370ef0c522982104c269cb44dd4d0e69400093c (diff)
- Fix for file inputs without values (forms).
Diffstat (limited to 'src')
-rw-r--r--src/form.cc81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/form.cc b/src/form.cc
index f764c563..3fbb6360 100644
--- a/src/form.cc
+++ b/src/form.cc
@@ -1059,41 +1059,42 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit)
DilloHtmlInput *input = inputs->get (i);
Dstr *name = dStr_new(input->name);
bool is_active_submit = (input == active_submit);
+ int valcount;
name = encodeText(char_encoder, &name);
input->appendValuesTo(values, is_active_submit);
- if (input->type == DILLO_HTML_INPUT_FILE && dList_length(values) >0) {
- if (dList_length(values) > 1)
- MSG_WARN("multiple files per form control not supported\n");
- Dstr *file = (Dstr *) dList_nth_data(values, 0);
- dList_remove(values, file);
+ if ((valcount = dList_length(values)) > 0) {
+ if (input->type == DILLO_HTML_INPUT_FILE) {
+ if (valcount > 1)
+ MSG_WARN("multiple files per form control not supported\n");
+ Dstr *file = (Dstr *) dList_nth_data(values, 0);
+ dList_remove(values, file);
- /* Get filename and encode it. Do not encode file contents. */
- LabelButtonResource *lbr =
+ /* Get filename and encode it. Do not encode file contents. */
+ LabelButtonResource *lbr =
(LabelButtonResource*) input->embed->getResource();
- const char *filename = lbr->getLabel();
- if (filename[0] && strcmp(filename, input->init_str)) {
- char *p = strrchr(filename, '/');
- if (p)
- filename = p + 1; /* don't reveal path */
- Dstr *dfilename = dStr_new(filename);
- dfilename = encodeText(char_encoder, &dfilename);
- filesInputMultipartAppend(DataStr, boundary, name->str,
- file, dfilename->str);
- dStr_free(dfilename, 1);
- }
- dStr_free(file, 1);
- } else if (input->type == DILLO_HTML_INPUT_INDEX) {
- /* no name */
- Dstr *val = (Dstr *) dList_nth_data(values, 0);
- dList_remove(values, val);
- val = encodeText(char_encoder, &val);
- strUrlencodeAppend(DataStr, val->str);
- dStr_free(val, 1);
- } else if (input->type == DILLO_HTML_INPUT_IMAGE) {
- if (dList_length(values) > 0) {
+ const char *filename = lbr->getLabel();
+ if (filename[0] && strcmp(filename, input->init_str)) {
+ char *p = strrchr(filename, '/');
+ if (p)
+ filename = p + 1; /* don't reveal path */
+ Dstr *dfilename = dStr_new(filename);
+ dfilename = encodeText(char_encoder, &dfilename);
+ filesInputMultipartAppend(DataStr, boundary, name->str,
+ file, dfilename->str);
+ dStr_free(dfilename, 1);
+ }
+ dStr_free(file, 1);
+ } else if (input->type == DILLO_HTML_INPUT_INDEX) {
+ /* no name */
+ Dstr *val = (Dstr *) dList_nth_data(values, 0);
+ dList_remove(values, val);
+ val = encodeText(char_encoder, &val);
+ strUrlencodeAppend(DataStr, val->str);
+ dStr_free(val, 1);
+ } else if (input->type == DILLO_HTML_INPUT_IMAGE) {
Dstr *x, *y;
x = (Dstr *) dList_nth_data(values, 0);
dList_remove(values, x);
@@ -1105,18 +1106,18 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit)
imageInputMultipartAppend(DataStr, boundary, name, x, y);
dStr_free(x, 1);
dStr_free(y, 1);
- }
- } else {
- int length = dList_length(values), i;
- for (i = 0; i < length; i++) {
- Dstr *val = (Dstr *) dList_nth_data(values, 0);
- dList_remove(values, val);
- val = encodeText(char_encoder, &val);
- if (content_type == DILLO_HTML_ENC_URLENCODED)
- inputUrlencodeAppend(DataStr, name->str, val->str);
- else if (content_type == DILLO_HTML_ENC_MULTIPART)
- inputMultipartAppend(DataStr, boundary, name->str, val->str);
- dStr_free(val, 1);
+ } else {
+ for (int j = 0; j < valcount; j++) {
+ Dstr *val = (Dstr *) dList_nth_data(values, 0);
+ dList_remove(values, val);
+ val = encodeText(char_encoder, &val);
+ if (content_type == DILLO_HTML_ENC_URLENCODED)
+ inputUrlencodeAppend(DataStr, name->str, val->str);
+ else if (content_type == DILLO_HTML_ENC_MULTIPART)
+ inputMultipartAppend(DataStr, boundary, name->str,
+ val->str);
+ dStr_free(val, 1);
+ }
}
}
dStr_free(name, 1);