diff options
author | Martin Petersson <Martin.Petersson@nokia.com> | 2012-06-08 10:39:37 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-03 01:09:33 +0200 |
commit | 6c59cdecee42dad1e100857314d28a3d8279a164 (patch) | |
tree | 834b54e0197a443d88ab056bfe4bac85128bb12a /src/network | |
parent | 41064f851591d9437baeda502b6e2504fee8f213 (diff) |
QSslCertificate::fromPath fix wildcard handling
The reqExp used to handle wildcards in the path was broken. So we
always searched the working directory and not the specified path.
Autotest where passing because of a hack used for Windows paths
where we removed the first two chars in the path string.
This fix will not use nativeSeparators thus removing the Windows hack
and fix the regExp to match wildcard chars.
Task-number: QTBUG-23573
Change-Id: I56fadbb67f25b8ce9c0f17cb6232e0bdb9148b1c
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/ssl/qsslcertificate.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 105cb4b323..1b9563b0f5 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -843,39 +843,46 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path, QRegExp::PatternSyntax syntax) { // $, (,), *, +, ., ?, [, ,], ^, {, | and }. + + // make sure to use the same path separators on Windows and Unix like systems. + QString sourcePath = QDir::fromNativeSeparators(path); + + // Find the path without the filename + QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(QLatin1Char('/'))); + + // Check if the path contains any special chars int pos = -1; if (syntax == QRegExp::Wildcard) - pos = path.indexOf(QRegExp(QLatin1String("[^\\][\\*\\?\\[\\]]"))); + pos = pathPrefix.indexOf(QRegExp(QLatin1String("[*?[]"))); else if (syntax != QRegExp::FixedString) - pos = path.indexOf(QRegExp(QLatin1String("[^\\][\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]"))); - QString pathPrefix = path.left(pos); // == path if pos < 0 - if (pos != -1) - pathPrefix = pathPrefix.left(pathPrefix.lastIndexOf(QLatin1Char('/'))); - - // Special case - if the prefix ends up being nothing, use "." instead and - // chop off the first two characters from the glob'ed paths. - int startIndex = 0; - if (pathPrefix.trimmed().isEmpty()) { - if(path.startsWith(QLatin1Char('/'))) { - pathPrefix = path.left(path.indexOf(QRegExp(QLatin1String("[\\*\\?\\[]")))); - pathPrefix = path.left(path.lastIndexOf(QLatin1Char('/'))); - } else { - startIndex = 2; - pathPrefix = QLatin1String("."); + pos = sourcePath.indexOf(QRegExp(QLatin1String("[\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]"))); + if (pos != -1) { + // there was a special char in the path so cut of the part containing that char. + pathPrefix = pathPrefix.left(pos); + if (pathPrefix.contains(QLatin1Char('/'))) + pathPrefix = pathPrefix.left(pathPrefix.lastIndexOf(QLatin1Char('/'))); + else + pathPrefix.clear(); + } else { + // Check if the path is a file. + if (QFileInfo(sourcePath).isFile()) { + QFile file(sourcePath); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + return QSslCertificate::fromData(file.readAll(),format); + return QList<QSslCertificate>(); } } - // The path is a file. - if (pos == -1 && QFileInfo(pathPrefix).isFile()) { - QFile file(pathPrefix); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - return QSslCertificate::fromData(file.readAll(),format); - return QList<QSslCertificate>(); + // Special case - if the prefix ends up being nothing, use "." instead. + int startIndex = 0; + if (pathPrefix.isEmpty()) { + pathPrefix = QLatin1String("."); + startIndex = 2; } // The path can be a file or directory. QList<QSslCertificate> certs; - QRegExp pattern(path, Qt::CaseSensitive, syntax); + QRegExp pattern(sourcePath, Qt::CaseSensitive, syntax); QDirIterator it(pathPrefix, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); while (it.hasNext()) { QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex); |