Fix url encoded query generation, when there's no name/value pairs.

This commit is contained in:
Michael Drake 2012-10-16 18:32:14 +01:00
parent c41ff369ff
commit 88dd7c3709
1 changed files with 5 additions and 4 deletions

View File

@ -684,7 +684,7 @@ static char *form_url_encode(struct form *form,
{
char *name, *value;
char *s, *s2;
unsigned int len, len1;
unsigned int len, len1, len_init;
url_func_result url_err;
if (query_string)
@ -698,10 +698,10 @@ static char *form_url_encode(struct form *form,
if (query_string) {
s[0] = '?';
s[1] = '\0';
len = 1;
len_init = len = 1;
} else {
s[0] = '\0';
len = 0;
len_init = len = 0;
}
for (; control; control = control->next) {
@ -737,7 +737,8 @@ static char *form_url_encode(struct form *form,
free(value);
}
if (len)
if (len > len_init)
/* Replace trailing '&' */
s[len - 1] = '\0';
return s;
}