Merge pull request #8932 from nextcloud/bugfix/8929/fileshare-detection

fix(account): do not consider URLs with a trailing slash as public links
This commit is contained in:
Jyrki Gadinger 2025-10-23 13:50:10 +02:00 committed by GitHub
commit 06b87b679d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -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));

View File

@ -40,6 +40,35 @@ private slots:
AccountPtr account = Account::create();
[[maybe_unused]] const auto davPath = account->davPath();
}
void testAccount_isPublicShareLink_data()
{
QTest::addColumn<QString>("url");
QTest::addColumn<bool>("expectedResult");
QTest::addColumn<QString>("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)