From 0d7f65edc58fb61311a707abd51d25e8af17ff3a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 23 Apr 2012 17:46:29 +0200 Subject: [PATCH] Don't use the QRegExp methods that modify the object [Assistant] QRegExp matching methods modify the object, which we don't want to. In particular, when we receive a QRegExp from the user or we store in a context that might require thread-safety, make sure we make a copy before using it. QRegularExpression has no such shortcoming. Task-number: QTBUG-25064 Change-Id: I63bdca450db06adf1935672ca678b779cd89f961 Reviewed-by: Karsten Heimrich --- src/assistant/help/qhelp_global.cpp | 2 +- src/assistant/help/qhelpgenerator.cpp | 2 +- src/assistant/help/qhelpsearchquerywidget.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/assistant/help/qhelp_global.cpp b/src/assistant/help/qhelp_global.cpp index 05c8aac..b2a4227 100644 --- a/src/assistant/help/qhelp_global.cpp +++ b/src/assistant/help/qhelp_global.cpp @@ -108,7 +108,7 @@ QString QHelpGlobal::codecFromHtmlData(const QByteArray &data) QString QHelpGlobal::codecFromXmlData(const QByteArray &data) { QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size())); - const QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version=" + QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version=" "\"\\d\\.\\d\" encoding=\"([^\"]+)\"\\?>.*")); return encodingExp.exactMatch(head) ? encodingExp.cap(1) : QString(); } diff --git a/src/assistant/help/qhelpgenerator.cpp b/src/assistant/help/qhelpgenerator.cpp index 1586fd3..17d7d74 100644 --- a/src/assistant/help/qhelpgenerator.cpp +++ b/src/assistant/help/qhelpgenerator.cpp @@ -876,7 +876,7 @@ bool QHelpGenerator::checkLinks(const QHelpDataInterface &helpData) emit warning(tr("File '%1' cannot be opened.").arg(fileName)); continue; } - const QRegExp linkPattern(QLatin1String("<(?:a href|img src)=\"?([^#\">]+)[#\">]")); + QRegExp linkPattern(QLatin1String("<(?:a href|img src)=\"?([^#\">]+)[#\">]")); QTextStream stream(&htmlFile); const QString codec = QHelpGlobal::codecFromData(htmlFile.read(1000)); stream.setCodec(QTextCodec::codecForName(codec.toLatin1().constData())); diff --git a/src/assistant/help/qhelpsearchquerywidget.cpp b/src/assistant/help/qhelpsearchquerywidget.cpp index 875b551..741dba0 100644 --- a/src/assistant/help/qhelpsearchquerywidget.cpp +++ b/src/assistant/help/qhelpsearchquerywidget.cpp @@ -161,7 +161,7 @@ private: if (s) searchTerm.replace(phrase, phrase.mid(1)); - const QRegExp exp(QLatin1String("\\s+")); + QRegExp exp(QLatin1String("\\s+")); wordList += searchTerm.split(exp, QString::SkipEmptyParts); return wordList; } @@ -285,7 +285,7 @@ private slots: queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, buildTermList(defaultQuery->text()))); } else { - const QRegExp exp(QLatin1String("\\s+")); + QRegExp exp(QLatin1String("\\s+")); QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts); if (!lst.isEmpty()) { -- 2.7.4