summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Petry <PVince81@yahoo.fr>2021-01-05 12:04:08 +0100
committerVincent Petry <PVince81@yahoo.fr>2021-01-05 12:04:08 +0100
commit74b2fc7fdca9be13cbbe4cb52b2fab573b3cf82c (patch)
tree985086fc8bf2afe7185a8017cc65ff609614e788 /src
parent216f62ea1468933f4a78f17885b27e37e1393d8c (diff)
Use uri_has_scheme for Webdav response href
Use uri_has_scheme to find out if the href in Webdav responses is absolute to use the matching base path extraction. Signed-off-by: Vincent Petry <PVince81@yahoo.fr>
Diffstat (limited to 'src')
-rw-r--r--src/storage/plugins/CurlStorage.cxx19
-rw-r--r--src/util/UriExtract.cxx2
-rw-r--r--src/util/UriExtract.hxx2
3 files changed, 11 insertions, 12 deletions
diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx
index 298d70967..d717a824c 100644
--- a/src/storage/plugins/CurlStorage.cxx
+++ b/src/storage/plugins/CurlStorage.cxx
@@ -516,7 +516,6 @@ private:
*/
gcc_pure
StringView HrefToEscapedName(const char *href) const noexcept {
- StringView relative_path;
StringView path = uri_get_path(href);
if (path == nullptr)
return nullptr;
@@ -524,23 +523,23 @@ private:
/* kludge: ignoring case in this comparison to avoid
false negatives if the web server uses a different
case */
- relative_path = StringAfterPrefixIgnoreCase(path, base_path.c_str());
- if (relative_path == nullptr || relative_path.empty()) {
- // try relative base path
- relative_path = StringAfterPrefixIgnoreCase(path, base_path_relative.c_str());
+ if (uri_has_scheme(path)) {
+ path = StringAfterPrefixIgnoreCase(path, base_path.c_str());
+ } else {
+ path = StringAfterPrefixIgnoreCase(path, base_path_relative.c_str());
}
- if (relative_path == nullptr || relative_path.empty()) {
+ if (path == nullptr || path.empty()) {
return nullptr;
}
- const char *slash = relative_path.Find('/');
+ const char *slash = path.Find('/');
if (slash == nullptr)
/* regular file */
- return relative_path;
- else if (slash == &relative_path.back())
+ return path;
+ else if (slash == &path.back())
/* trailing slash: collection; strip the slash */
- return {relative_path.data, slash};
+ return {path.data, slash};
else
/* strange, better ignore it */
return nullptr;
diff --git a/src/util/UriExtract.cxx b/src/util/UriExtract.cxx
index 053c20cc7..ab8a7244a 100644
--- a/src/util/UriExtract.cxx
+++ b/src/util/UriExtract.cxx
@@ -85,7 +85,7 @@ uri_after_scheme(std::string_view uri) noexcept
}
bool
-uri_has_scheme(const char *uri) noexcept
+uri_has_scheme(std::string_view uri) noexcept
{
return !uri_get_scheme(uri).empty();
}
diff --git a/src/util/UriExtract.hxx b/src/util/UriExtract.hxx
index 05e288b30..5f17910ea 100644
--- a/src/util/UriExtract.hxx
+++ b/src/util/UriExtract.hxx
@@ -40,7 +40,7 @@
*/
gcc_pure
bool
-uri_has_scheme(const char *uri) noexcept;
+uri_has_scheme(std::string_view uri) noexcept;
/**
* Returns the scheme name of the specified URI, or an empty string.