forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user