From 17f1a41519074f63b3cbd55851db4e8cc5be5e0a Mon Sep 17 00:00:00 2001 From: lda Date: Sat, 2 Dec 2023 10:25:28 -0500 Subject: [PATCH] `HttpRouter`: Decode path parts before matching. (#19) Required by Telodendria/Telodendria#44. Reviewed-on: https://git.telodendria.io/Telodendria/Cytoplasm/pulls/19 Co-authored-by: lda Co-committed-by: lda --- src/HttpRouter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/HttpRouter.c b/src/HttpRouter.c index 981a0f8..ef16399 100644 --- a/src/HttpRouter.c +++ b/src/HttpRouter.c @@ -23,6 +23,7 @@ */ #include +#include #include #include #include @@ -228,12 +229,15 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) regmatch_t pmatch[REG_MAX_SUB]; + pathPart = HttpUrlDecode(pathPart); + i = 0; while (HashMapIterateReentrant(node->children, &key, (void **) &val, &i)) { if (regexec(&val->regex, pathPart, REG_MAX_SUB, pmatch, 0) == 0) { + Free(pathPart); break; } @@ -243,6 +247,7 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) if (!val) { exec = NULL; + Free(pathPart); break; } @@ -263,12 +268,14 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) substr = StrSubstr(pathPart, cpmatch.rm_so, cpmatch.rm_eo); if (pmatch[i].rm_so == -1) { + Free(pathPart); break; } ArrayAdd(matches, substr); } } + Free(pathPart); } Free(path); }