summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorck <qt-info@nokia.com>2010-04-08 11:37:02 (GMT)
committerck <qt-info@nokia.com>2010-04-08 13:13:18 (GMT)
commit0fefefd33bb252c0d30222df64223d2e92888e8d (patch)
tree927feaa2947cbe0f7c57b9d4d2a6048f6bed53fa
parentf3b4ea8bb2940a8d95c29fa6d16b08313b8d033f (diff)
downloadQt-0fefefd33bb252c0d30222df64223d2e92888e8d.zip
Qt-0fefefd33bb252c0d30222df64223d2e92888e8d.tar.gz
Qt-0fefefd33bb252c0d30222df64223d2e92888e8d.tar.bz2
Assistant: Check namespace and virtual folder syntax of help projects.
Task-number: QTBUG-4519 Reviewed-by: kh1
-rw-r--r--tools/assistant/lib/qhelpprojectdata.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/tools/assistant/lib/qhelpprojectdata.cpp b/tools/assistant/lib/qhelpprojectdata.cpp
index 83491a0..b0faf0c 100644
--- a/tools/assistant/lib/qhelpprojectdata.cpp
+++ b/tools/assistant/lib/qhelpprojectdata.cpp
@@ -47,6 +47,7 @@
#include <QtCore/QStack>
#include <QtCore/QMap>
#include <QtCore/QRegExp>
+#include <QtCore/QUrl>
#include <QtCore/QVariant>
#include <QtXml/QXmlStreamReader>
@@ -77,6 +78,7 @@ private:
void readFiles();
void raiseUnknownTokenError();
void addMatchingFiles(const QString &pattern);
+ bool hasValidSyntax(const QString &nameSpace, const QString &vFolder) const;
QMap<QString, QStringList> dirEntriesCache;
};
@@ -115,16 +117,14 @@ void QHelpProjectDataPrivate::readProject()
if (isStartElement()) {
if (name() == QLatin1String("virtualFolder")) {
virtualFolder = readElementText();
- if (virtualFolder.contains(QLatin1String("/")))
+ if (!hasValidSyntax(QLatin1String("test"), virtualFolder))
raiseError(QCoreApplication::translate("QHelpProject",
- "A virtual folder must not contain "
- "a \'/\' character!"));
+ "Virtual folder has invalid syntax."));
} else if (name() == QLatin1String("namespace")) {
namespaceName = readElementText();
- if (namespaceName.contains(QLatin1String("/")))
+ if (!hasValidSyntax(namespaceName, QLatin1String("test")))
raiseError(QCoreApplication::translate("QHelpProject",
- "A namespace must not contain a "
- "\'/\' character!"));
+ "Namespace has invalid syntax."));
} else if (name() == QLatin1String("customFilter")) {
readCustomFilter();
} else if (name() == QLatin1String("filterSection")) {
@@ -318,6 +318,22 @@ void QHelpProjectDataPrivate::addMatchingFiles(const QString &pattern)
filterSectionList.last().addFile(pattern);
}
+bool QHelpProjectDataPrivate::hasValidSyntax(const QString &nameSpace,
+ const QString &vFolder) const
+{
+ const QLatin1Char slash('/');
+ if (nameSpace.contains(slash) || vFolder.contains(slash))
+ return false;
+ QUrl url;
+ const QLatin1String scheme("qthelp");
+ url.setScheme(scheme);
+ url.setHost(nameSpace);
+ url.setPath(vFolder);
+
+ const QString expectedUrl(scheme + QLatin1String("://") + nameSpace + slash + vFolder);
+ return url.isValid() && url.toString() == expectedUrl;
+}
+
/*!
\internal
\class QHelpProjectData