Skip to content

Commit

Permalink
Properly check for webdav or dav path in provided host url for cmd.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Oct 11, 2024
1 parent 02f9acb commit 5e14c7c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 350 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/cmd.cpp:350:10 [cppcoreguidelines-init-variables]

variable 'hostUrl' is not initialized

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:[email protected]" << 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
Expand Down

0 comments on commit 5e14c7c

Please sign in to comment.