]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Properly check for webdav or dav path in provided host url for cmd.cpp
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 9 Oct 2024 01:47:03 +0000 (09:47 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 11 Oct 2024 06:02:36 +0000 (14:02 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/cmd/cmd.cpp

index b770c3796a8e5e4ce1dd9ed190de5ba843954853..cae496780074f34b99e35b0654a6077f30f1bf08 100644 (file)
@@ -344,15 +344,18 @@ int main(int argc, char **argv)
         return EXIT_FAILURE;
     }
 
-    if (options.target_url.contains("/webdav", Qt::CaseInsensitive) || options.target_url.contains("/dav", Qt::CaseInsensitive)) {
+    const auto sanitisedTargetUrl = options.target_url.endsWith('/') || options.target_url.endsWith('\\') 
+        ? options.target_url.chopped(1) 
+        : options.target_url;
+    QUrl hostUrl = QUrl::fromUserInput(sanitisedTargetUrl);
+
+    if (const auto hostUrlPath = hostUrl.path(); hostUrlPath.contains("/webdav", Qt::CaseInsensitive) || hostUrlPath.contains("/dav", Qt::CaseInsensitive)) {
         qWarning("Dav or webdav in server URL.");
         std::cerr << "Error! Please specify only the base URL of your host with username and password. Example:" << std::endl
                   << "https://username:password@cloud.example.com" << std::endl;
         return EXIT_FAILURE;
     }
 
-    QUrl hostUrl = QUrl::fromUserInput((options.target_url.endsWith(QLatin1Char('/')) || options.target_url.endsWith(QLatin1Char('\\'))) ? options.target_url.chopped(1) : options.target_url);
-
     // Order of retrieval attempt (later attempts override earlier ones):
     // 1. From URL
     // 2. From options