]> Eric's Git Repo - listv4.git/commitdiff
Fixing query string issue
authorEric Wertz <ericwertz@Erics-MacBook-Pro.local>
Sun, 8 Jun 2025 20:37:24 +0000 (16:37 -0400)
committerEric Wertz <ericwertz@Erics-MacBook-Pro.local>
Sun, 8 Jun 2025 20:37:24 +0000 (16:37 -0400)
backend/StaticFileResponse.cpp

index 1c32cfdbe5b7d8253a866b9e1e5a97a21a62403d..19e3f0e88cd999846b65a90bffa49c1e404addfc 100644 (file)
 // 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]);