diff --git a/util/http/http.c b/util/http/http.c index 56de433..799593e 100644 --- a/util/http/http.c +++ b/util/http/http.c @@ -103,9 +103,31 @@ static void *http_get_param_fn(struct http_worker_s *worker, FILE *stream, const return NULL; } +// Helper function to decode percent-encoded strings +static void http_url_decode(const char *in, char *out) +{ + while (*in) { + if (*in == '%' && isxdigit(in[1]) && isxdigit(in[2])) { + char hex[3] = {in[1], in[2], '\0'}; + *out++ = (char)strtoul(hex, NULL, 16); + in += 3; + } else if (*in == '+') { + *out++ = ' '; + in++; + } else { + *out++ = *in++; + } + } + *out = '\0'; +} + char *http_get_param(http_worker_t *worker, const char *key) { - return http_enum_params(worker, NULL, http_get_param_fn, (void*)key); + char *param = http_enum_params(worker, NULL, http_get_param_fn, (void*)key); + if (param) { + http_url_decode(param, param); + } + return param; } static void http_process(http_worker_t *worker, FILE *stream) diff --git a/util/http/http.h b/util/http/http.h index a26a66a..c73dc51 100644 --- a/util/http/http.h +++ b/util/http/http.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include