From 9bdb84523c77480ec353487fcf1315b24b5261d9 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 3 Aug 2019 15:45:49 -0700 Subject: [PATCH] modules/web_root: Relax trailing slash requirement in conf item string. --- modules/web_root.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/web_root.cc b/modules/web_root.cc index 38b5b6bcd..cdf842402 100644 --- a/modules/web_root.cc +++ b/modules/web_root.cc @@ -108,14 +108,24 @@ init_files() return; } - for(const auto &file : fs::ls_r(path)) + for(const auto &absolute : fs::ls_r(path)) { - const auto name + // fs::ls_r() gives us full absolute paths on the system, but we need + // to locate resources relative to webroot. The system path below + // the configured webroot is stripped here. + auto relative { - lstrip(file, path) + lstrip(absolute, path) }; - files.emplace(std::string(name), file); + // The configured webroot is a directory string entered by the admin, it + // may or may not contain a trailing slash. This the strip above may have + // left a leading slash on this name; which is bad. + relative = lstrip(relative, '/'); + + // Add the mapping of the relative resource path to the absolute path + // on the system. + files.emplace(relative, absolute); } if(files.empty())