From 0fefefd33bb252c0d30222df64223d2e92888e8d Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 8 Apr 2010 13:37:02 +0200 Subject: Assistant: Check namespace and virtual folder syntax of help projects. Task-number: QTBUG-4519 Reviewed-by: kh1 --- tools/assistant/lib/qhelpprojectdata.cpp | 28 ++++++++++++++++++++++------ 1 file 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 #include #include +#include #include #include @@ -77,6 +78,7 @@ private: void readFiles(); void raiseUnknownTokenError(); void addMatchingFiles(const QString &pattern); + bool hasValidSyntax(const QString &nameSpace, const QString &vFolder) const; QMap 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 -- cgit v0.12