From 5a1d8a1dcf3d7b087532ff8d4d94341810110b9b Mon Sep 17 00:00:00 2001 From: Quinten Date: Wed, 5 Nov 2025 15:18:45 +0100 Subject: [PATCH] fix: use correct location match segment --- webserv/handler/URI.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index 61af3b1..00adedd 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -36,14 +36,19 @@ const AConfig *URI::matchConfig(const std::string &uri, const ServerConfig &serv { return serverConfig.getLocation(locationPath); } - // TODO this matches only prefix, need to handle exact match - if (uri.starts_with(utils::trim(locationPath, "/"))) + if (!uri.starts_with(utils::trim(locationPath, "/"))) { - if (locationPath.length() > maxMatchLength) - { - maxMatchLength = locationPath.length(); - bestMatch = serverConfig.getLocation(locationPath); - } + continue; + } + if (uri.substr(utils::trim(locationPath, "/").length())[0] != '/' + || !uri.substr(utils::trim(locationPath, "/").length()).empty()) + { + continue; + } + if (locationPath.length() > maxMatchLength) + { + maxMatchLength = locationPath.length(); + bestMatch = serverConfig.getLocation(locationPath); } } return bestMatch;