main.c: URL-encode created directories

Otherwise, directories with special characters, such as "%", would not
be accessible when performing the redirection.
This commit is contained in:
Xavier Del Campo Romero 2024-02-19 23:07:16 +01:00
parent a578ad6537
commit 1f8aa578a4
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
1 changed files with 8 additions and 1 deletions

9
main.c
View File

@ -1356,6 +1356,7 @@ static int createdir(const struct http_payload *const p,
struct dynstr d, userd;
struct form *forms = NULL;
size_t n = 0;
char *encurl = NULL;
dynstr_init(&d);
dynstr_init(&userd);
@ -1469,7 +1470,12 @@ static int createdir(const struct http_payload *const p,
.status = HTTP_STATUS_SEE_OTHER
};
if (http_response_add_header(r, "Location", userd.str))
if (!(encurl = http_encode_url(userd.str)))
{
fprintf(stderr, "%s: http_encode_url failed\n", __func__);
goto end;
}
else if (http_response_add_header(r, "Location", encurl))
{
fprintf(stderr, "%s: http_response_add_header failed\n", __func__);
goto end;
@ -1482,6 +1488,7 @@ end:
forms_free(forms, n);
dynstr_free(&userd);
dynstr_free(&d);
free(encurl);
return ret;
}