From bddb39df16295540ba63fba9d3c32c46d252f635 Mon Sep 17 00:00:00 2001 From: Jyrki Gadinger Date: Thu, 23 Oct 2025 11:57:10 +0200 Subject: [PATCH] fix(account): do not consider URLs with a trailing slash as public links Resolves #8929 Signed-off-by: Jyrki Gadinger --- src/libsync/account.cpp | 2 +- test/testaccount.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 2c254a8685..08530a00d7 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -557,7 +557,7 @@ void Account::setSslErrorHandler(AbstractSslErrorHandler *handler) void Account::setUrl(const QUrl &url) { - const QRegularExpression discoverPublicLinks(R"(((https|http)://[^/]*).*/s/([^/]*))"); + const QRegularExpression discoverPublicLinks(R"(((https|http)://[^/]*).*/s/([^/]*)$)"); const auto isPublicLink = discoverPublicLinks.match(url.toString()); if (isPublicLink.hasMatch()) { _url = QUrl::fromUserInput(isPublicLink.captured(1)); diff --git a/test/testaccount.cpp b/test/testaccount.cpp index e0a88623ae..670b6553de 100644 --- a/test/testaccount.cpp +++ b/test/testaccount.cpp @@ -40,6 +40,35 @@ private slots: AccountPtr account = Account::create(); [[maybe_unused]] const auto davPath = account->davPath(); } + + void testAccount_isPublicShareLink_data() + { + QTest::addColumn("url"); + QTest::addColumn("expectedResult"); + QTest::addColumn("expectedDavUser"); + + QTest::newRow("plain URL") << "https://example.com" << false << ""; + QTest::newRow("plain URL, trailing slash") << "https://example.com/" << false << ""; + QTest::newRow("share link") << "https://example.com/s/rPZLaTKfWct37Nd" << true << "rPZLaTKfWct37Nd"; + QTest::newRow("share link, trailing slash") << "https://example.com/s/rPZLaTKfWct37Nd/" << false << ""; + QTest::newRow("subpath containing /s/ (looks like share link)") << "https://example.com/s/nextcloud" << true << "nextcloud"; + QTest::newRow("subpath containing /s/, trailing slash") << "https://example.com/s/nextcloud/" << false << ""; + QTest::newRow("subpath containing /s/, share link") << "https://example.com/s/nextcloud/s/rPZLaTKfWct37Nd" << true << "rPZLaTKfWct37Nd"; + QTest::newRow("subpath containing /s/, share link, trailing slash") << "https://example.com/s/nextcloud/s/rPZLaTKfWct37Nd/" << false << ""; + } + + void testAccount_isPublicShareLink() + { + AccountPtr account = Account::create(); + + QFETCH(QString, url); + QFETCH(bool, expectedResult); + QFETCH(QString, expectedDavUser); + + account->setUrl(QUrl{url}); + QCOMPARE(account->isPublicShareLink(), expectedResult); + QCOMPARE(account->davUser(), expectedDavUser); + } }; QTEST_APPLESS_MAIN(TestAccount)