From 20a39c16f236f999cd1694cdc47a3739efcbbfe4 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Tue, 15 Jun 2010 13:39:25 +0200 Subject: Temporary fix for regression in QSslCertificate::fromPath() The regression was introduced with 164f347aba7287407615223dc2219a016ebc8248. As soon as possible we should probably rewrite the fromPath() function, to have a proper solution. Nevertheless this might be a bigger change and should not be done so late in release cycle. Reviewed-by: TrustMe --- src/network/ssl/qsslcertificate.cpp | 11 ++++++++--- tests/auto/qsslcertificate/tst_qsslcertificate.cpp | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index ed12e00..a3ea555 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -537,7 +537,7 @@ QList QSslCertificate::fromPath(const QString &path, // $, (,), *, +, ., ?, [, ,], ^, {, | and }. int pos = -1; if (syntax == QRegExp::Wildcard) - pos = path.indexOf(QRegExp(QLatin1String("[\\*\\?\\[]"))); + pos = path.indexOf(QRegExp(QLatin1String("[^\\][\\*\\?\\[\\]]"))); else if (syntax != QRegExp::FixedString) pos = path.indexOf(QRegExp(QLatin1String("[^\\][\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]"))); QString pathPrefix = path.left(pos); // == path if pos < 0 @@ -548,8 +548,13 @@ QList QSslCertificate::fromPath(const QString &path, // chop off the first two characters from the glob'ed paths. int startIndex = 0; if (pathPrefix.trimmed().isEmpty()) { - startIndex = 2; - pathPrefix = QLatin1String("."); + if(path.startsWith(QLatin1Char('/'))) { + pathPrefix = path.left(path.indexOf(QRegExp(QLatin1String("[\\*\\?\\[]")))); + pathPrefix = path.left(path.lastIndexOf(QLatin1Char('/'))); + } else { + startIndex = 2; + pathPrefix = QLatin1String("."); + } } // The path is a file. diff --git a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp index 505b867..d0509bb 100644 --- a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp @@ -542,6 +542,9 @@ void tst_QSslCertificate::fromPath_data() QTest::newRow("\"d.*/c.*.pem\" regexp der") << QString("d.*/c.*.pem") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0; +#ifdef Q_OS_LINUX + QTest::newRow("absolute path wildcard pem") << QString(QDir::currentPath() + "/certificates/*.pem") << int(QRegExp::Wildcard) << true << 4; +#endif QTest::newRow("trailing-whitespace") << QString("more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1; QTest::newRow("no-ending-newline") << QString("more-certificates/no-ending-newline.pem") << int(QRegExp::FixedString) << true << 1; -- cgit v0.12