Beautifier: Fix possible endless loop

Change-Id: Ib2f98c2d761ea9abfd6a42ec30cf8318ee7bd575
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
Lorenz Haas
2014-02-19 06:48:37 +01:00
committed by David Schulz
parent 88309188c1
commit a142270d2c

View File

@@ -59,9 +59,12 @@ void ConfigurationSyntaxHighlighter::setKeywords(const QStringList &keywords)
if (keywords.isEmpty()) if (keywords.isEmpty())
return; return;
// Check for empty keywords since they can cause an endless loop in highlightBlock().
QStringList pattern; QStringList pattern;
for (int i = 0, total = keywords.count(); i < total; ++i) foreach (const QString &word, keywords) {
pattern << QRegExp::escape(keywords.at(i)); if (!word.isEmpty())
pattern << QRegExp::escape(word);
}
m_expressionKeyword.setPattern(QLatin1String("(?:\\s|^)(") + pattern.join(QLatin1String("|")) m_expressionKeyword.setPattern(QLatin1String("(?:\\s|^)(") + pattern.join(QLatin1String("|"))
+ QLatin1String(")(?=\\s|\\:|\\=|\\,|$)")); + QLatin1String(")(?=\\s|\\:|\\=|\\,|$)"));