From 5eb00ab25a2c9b933d2f52a30a6a180ae9369e9d Mon Sep 17 00:00:00 2001 From: Eric Wertz Date: Sun, 8 Jun 2025 16:37:24 -0400 Subject: [PATCH] Fixing query string issue --- backend/StaticFileResponse.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/StaticFileResponse.cpp b/backend/StaticFileResponse.cpp index 1c32cfd..19e3f0e 100644 --- a/backend/StaticFileResponse.cpp +++ b/backend/StaticFileResponse.cpp @@ -17,8 +17,15 @@ // CStaticFileResponse Implementation CStaticFileResponse::CStaticFileResponse(const CHTTPRequest& request, std::string path) : CHTTPResponse(request) { + // Remove query string from path for routing decisions + std::string clean_path = path; + size_t query_pos = clean_path.find('?'); + if (query_pos != std::string::npos) { + clean_path = clean_path.substr(0, query_pos); + } + // Index is easy enough to handle - if (path == "/") + if (clean_path == "/" ) { serveFileFromPath("index.html"); return; @@ -37,9 +44,9 @@ std::string CStaticFileResponse::sanitizePath(const std::string& requested_path) } // Basic path normalization - remove duplicate slashes and handle relative paths - std::string normalized; + std::string normalized = "/"; for (size_t i = 0; i < path.length(); i++) { - if (path[i] == '/' && !normalized.empty() && normalized.back() == '/') { + if (path[i] == '/' && normalized.back() == '/') { continue; // Skip duplicate slashes } normalized.push_back(path[i]); -- 2.49.0