]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_httpd.cpp
index efed34799bb9ee1d1ee892da7a830fcbc7ffde12..f3ec3298bd8823b154b4c9fb5017159ba7bea800 100644 (file)
@@ -351,7 +351,32 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
                        return false;
 
                if (url.field_set & (1 << UF_PATH))
-                       out.path = uri.substr(url.field_data[UF_PATH].off, url.field_data[UF_PATH].len);
+               {
+                       // Normalise the path.
+                       std::vector<std::string> pathsegments;
+                       irc::sepstream pathstream(uri.substr(url.field_data[UF_PATH].off, url.field_data[UF_PATH].len), '/');
+                       for (std::string pathsegment; pathstream.GetToken(pathsegment); )
+                       {
+                               if (pathsegment == ".")
+                               {
+                                       // Stay at the current level.
+                                       continue;
+                               }
+
+                               if (pathsegment == "..")
+                               {
+                                       // Traverse up to the previous level.
+                                       if (!pathsegments.empty())
+                                               pathsegments.pop_back();
+                                       continue;
+                               }
+
+                               pathsegments.push_back(pathsegment);
+                       }
+
+                       out.path.reserve(url.field_data[UF_PATH].len);
+                       out.path.append("/").append(stdalgo::string::join(pathsegments, '/'));
+               }
 
                if (url.field_set & (1 << UF_FRAGMENT))
                        out.fragment = uri.substr(url.field_data[UF_FRAGMENT].off, url.field_data[UF_FRAGMENT].len);