aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/help/searchwidget.cpp
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2012-03-16 15:41:59 +0100
committerKarsten Heimrich <karsten.heimrich@nokia.com>2012-03-16 16:03:21 +0100
commit38fe616d857234845b9169576433c28aa54fee89 (patch)
treeae06b6b91bdac53de5b3f9891dbdc14d83416648 /src/plugins/help/searchwidget.cpp
parentd880c74554db7fb586fc00c571a313c994d42e61 (diff)
Curly-braces in "Help -> Search for..." crashes Creator.
Task-number: QTCREATORBUG-6212 We need to escape special characters that are used inside the search engine as field delimiter. As soon as the search engine proccesses the search string it will remove the character and we might end up with an invalid string, forcing it to throw an exception thats not catched. Change-Id: I8b66c87c3137a1f175ead5df85c7f53fdcb5193e Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Diffstat (limited to 'src/plugins/help/searchwidget.cpp')
-rw-r--r--src/plugins/help/searchwidget.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/plugins/help/searchwidget.cpp b/src/plugins/help/searchwidget.cpp
index 07b11cf2aac..236f25e6390 100644
--- a/src/plugins/help/searchwidget.cpp
+++ b/src/plugins/help/searchwidget.cpp
@@ -153,8 +153,33 @@ void SearchWidget::showEvent(QShowEvent *event)
void SearchWidget::search() const
{
- QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query();
- searchEngine->search(query);
+ static QStringList charsToEscapeList;
+ if (charsToEscapeList.isEmpty()) {
+ charsToEscapeList << QLatin1String("\\") << QLatin1String("+")
+ << QLatin1String("-") << QLatin1String("!") << QLatin1String("(")
+ << QLatin1String(")") << QLatin1String(":") << QLatin1String("^")
+ << QLatin1String("[") << QLatin1String("]") << QLatin1String("{")
+ << QLatin1String("}") << QLatin1String("~");
+ }
+
+ static QString escapeChar(QLatin1String("\\"));
+ static QRegExp regExp(QLatin1String("[\\+\\-\\!\\(\\)\\^\\[\\]\\{\\}~:]"));
+
+ QList<QHelpSearchQuery> escapedQueries;
+ const QList<QHelpSearchQuery> queries = searchEngine->queryWidget()->query();
+ foreach (const QHelpSearchQuery &query, queries) {
+ QHelpSearchQuery escapedQuery;
+ escapedQuery.fieldName = query.fieldName;
+ foreach (QString word, query.wordList) {
+ if (word.contains(regExp)) {
+ foreach (const QString &charToEscape, charsToEscapeList)
+ word.replace(charToEscape, escapeChar + charToEscape);
+ escapedQuery.wordList.append(word);
+ }
+ }
+ escapedQueries.append(escapedQuery);
+ }
+ searchEngine->search(escapedQueries);
}
void SearchWidget::searchingStarted()