From: Eric Wertz Date: Sun, 8 Jun 2025 20:37:24 +0000 (-0400) Subject: Fixing query string issue X-Git-Url: https://ericdwertz.com/git/?a=commitdiff_plain;h=5eb00ab25a2c9b933d2f52a30a6a180ae9369e9d;p=listv4.git Fixing query string issue --- 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]);