Remove relative path handling which was not needed

The original base relative path was introduced due to an erroneous test
where the URL started with three slashes: "https:///" instead of two,
which led to implementing handling for such cases but broke the two
slashes case.

This fix removes the base relative path handling because with two
slashes the path is anyway always relative to the host (aka absolute
URI, without host).

This reverts 216f62ea14 and part of 74b2fc7fdc

Signed-off-by: Vincent Petry <PVince81@yahoo.fr>
This commit is contained in:
Vincent Petry 2021-01-08 16:50:27 +01:00
parent e99f6b5b38
commit ec0d3ac95d
No known key found for this signature in database
GPG Key ID: E055D6A4D513575C
1 changed files with 4 additions and 20 deletions

View File

@ -468,19 +468,11 @@ CurlStorage::GetInfo(std::string_view uri_utf8, [[maybe_unused]] bool follow)
gcc_pure
static std::string_view
UriPathOrSlash(const char *uri, bool relative) noexcept
UriPathOrSlash(const char *uri) noexcept
{
auto path = uri_get_path(uri);
if (path.data() == nullptr)
path = "/";
else if (relative) {
// search after first slash
path = path.substr(1);
auto slash = path.find('/');
if (slash != std::string_view::npos)
path = path.substr(slash);
}
return path;
}
@ -489,15 +481,13 @@ UriPathOrSlash(const char *uri, bool relative) noexcept
*/
class HttpListDirectoryOperation final : public PropfindOperation {
const std::string base_path;
const std::string base_path_relative;
MemoryStorageDirectoryReader::List entries;
public:
HttpListDirectoryOperation(CurlGlobal &curl, const char *uri)
:PropfindOperation(curl, uri, 1),
base_path(CurlUnescape(GetEasy(), UriPathOrSlash(uri, false))),
base_path_relative(CurlUnescape(GetEasy(), UriPathOrSlash(uri, true))) {}
base_path(CurlUnescape(GetEasy(), UriPathOrSlash(uri))) {}
std::unique_ptr<StorageDirectoryReader> Perform() {
DeferStart();
@ -523,15 +513,9 @@ private:
/* kludge: ignoring case in this comparison to avoid
false negatives if the web server uses a different
case */
if (uri_has_scheme(path)) {
path = StringAfterPrefixIgnoreCase(path, base_path.c_str());
} else {
path = StringAfterPrefixIgnoreCase(path, base_path_relative.c_str());
}
if (path == nullptr || path.empty()) {
path = StringAfterPrefixIgnoreCase(path, base_path.c_str());
if (path == nullptr || path.empty())
return nullptr;
}
const char *slash = path.Find('/');
if (slash == nullptr)