From 1f8aa578a489905ed2d7443cfcdb73a3ff8d48ea Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 19 Feb 2024 23:07:16 +0100 Subject: main.c: URL-encode created directories Otherwise, directories with special characters, such as "%", would not be accessible when performing the redirection. --- main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index cdb1aed..b9f0b50 100644 --- a/main.c +++ b/main.c @@ -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; } -- cgit v1.2.3