diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-04-23 16:29:18 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-24 14:39:38 +0200 |
commit | c1623a0d42c9869e5a1d04081e7660722a863de5 (patch) | |
tree | 17a58be3a4c80b143add805b7ff8218daab61106 | |
parent | c18f589a757b2c4cb8c5e66a92f34ac005223cfe (diff) | |
download | qtxmlpatterns-c1623a0d42c9869e5a1d04081e7660722a863de5.tar.gz |
Don't use the QRegExp methods that modify the object
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: I2c4d5f4b60d6b3569568103cd7107cd2adaa3ae8
Reviewed-by: Giuseppe D'Angelo <dangelog@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/xmlpatterns/data/qabstractdatetime_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/data/qabstractduration_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/data/qderivedstring_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/functions/qpatternmatchingfns.cpp | 6 | ||||
-rw-r--r-- | src/xmlpatterns/functions/qpatternplatform.cpp | 2 | ||||
-rw-r--r-- | src/xmlpatterns/functions/qpatternplatform_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/parser/qquerytransformparser.cpp | 2 | ||||
-rw-r--r-- | src/xmlpatterns/parser/querytransformparser.ypp | 2 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdschemachecker.cpp | 2 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdschemaparser.cpp | 4 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdtypechecker.cpp | 20 | ||||
-rw-r--r-- | tests/auto/qxmlquery/tst_qxmlquery.cpp | 2 | ||||
-rw-r--r-- | tests/auto/xmlpatterns/tst_xmlpatterns.cpp | 2 | ||||
-rw-r--r-- | tools/xmlpatterns/qapplicationargumentparser.cpp | 2 |
14 files changed, 26 insertions, 26 deletions
diff --git a/src/xmlpatterns/data/qabstractdatetime_p.h b/src/xmlpatterns/data/qabstractdatetime_p.h index 9c4b9d1..6fc72c7 100644 --- a/src/xmlpatterns/data/qabstractdatetime_p.h +++ b/src/xmlpatterns/data/qabstractdatetime_p.h @@ -140,7 +140,7 @@ namespace QPatternist Q_ASSERT(exp.isValid()); } - const QRegExp regExp; + QRegExp regExp; const qint8 zoneOffsetSign; const qint8 zoneOffsetHour; const qint8 zoneOffsetMinute; diff --git a/src/xmlpatterns/data/qabstractduration_p.h b/src/xmlpatterns/data/qabstractduration_p.h index 1667db5..a13d3f7 100644 --- a/src/xmlpatterns/data/qabstractduration_p.h +++ b/src/xmlpatterns/data/qabstractduration_p.h @@ -116,7 +116,7 @@ namespace QPatternist Q_ASSERT(yearP == -1 || yearP == 2); } - const QRegExp regExp; + QRegExp regExp; const qint8 year; const qint8 month; const qint8 day; diff --git a/src/xmlpatterns/data/qderivedstring_p.h b/src/xmlpatterns/data/qderivedstring_p.h index 87d9a2a..5f54f83 100644 --- a/src/xmlpatterns/data/qderivedstring_p.h +++ b/src/xmlpatterns/data/qderivedstring_p.h @@ -262,7 +262,7 @@ namespace QPatternist { const QString simplified(lexical.trimmed()); - const QRegExp validate(QLatin1String("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")); + QRegExp validate(QLatin1String("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")); Q_ASSERT(validate.isValid()); if(validate.exactMatch(simplified)) diff --git a/src/xmlpatterns/functions/qpatternmatchingfns.cpp b/src/xmlpatterns/functions/qpatternmatchingfns.cpp index 41ffe54..27c7dd4 100644 --- a/src/xmlpatterns/functions/qpatternmatchingfns.cpp +++ b/src/xmlpatterns/functions/qpatternmatchingfns.cpp @@ -59,7 +59,7 @@ MatchesFN::MatchesFN() : PatternPlatform(2) Item MatchesFN::evaluateSingleton(const DynamicContext::Ptr &context) const { - const QRegExp regexp(pattern(context)); + QRegExp regexp(pattern(context)); QString input; const Item arg(m_operands.first()->evaluateSingleton(context)); @@ -75,7 +75,7 @@ ReplaceFN::ReplaceFN() : PatternPlatform(3) Item ReplaceFN::evaluateSingleton(const DynamicContext::Ptr &context) const { - const QRegExp regexp(pattern(context)); + QRegExp regexp(pattern(context)); QString input; const Item arg(m_operands.first()->evaluateSingleton(context)); @@ -219,7 +219,7 @@ Item::Iterator::Ptr TokenizeFN::evaluateSequence(const DynamicContext::Ptr &cont if(input.isEmpty()) return CommonValues::emptyIterator; - const QRegExp regExp(pattern(context)); + QRegExp regExp(pattern(context)); const QStringList result(input.split(regExp, QString::KeepEmptyParts)); return makeItemMappingIterator<Item>(ConstPtr(this), diff --git a/src/xmlpatterns/functions/qpatternplatform.cpp b/src/xmlpatterns/functions/qpatternplatform.cpp index 08dc2f1..e9bbfbb 100644 --- a/src/xmlpatterns/functions/qpatternplatform.cpp +++ b/src/xmlpatterns/functions/qpatternplatform.cpp @@ -115,7 +115,7 @@ PatternPlatform::PatternPlatform(const qint8 flagsPosition) : m_compiledParts(No { } -const QRegExp PatternPlatform::pattern(const DynamicContext::Ptr &context) const +QRegExp PatternPlatform::pattern(const DynamicContext::Ptr &context) const { if(m_compiledParts == FlagsAndPattern) /* This is the most common case. */ { diff --git a/src/xmlpatterns/functions/qpatternplatform_p.h b/src/xmlpatterns/functions/qpatternplatform_p.h index ede3c4e..4a7f087 100644 --- a/src/xmlpatterns/functions/qpatternplatform_p.h +++ b/src/xmlpatterns/functions/qpatternplatform_p.h @@ -113,7 +113,7 @@ namespace QPatternist * settings its flags, and everything else required for getting it ready to use. If an error * occurs, an appropriate error is raised via @p context. */ - const QRegExp pattern(const DynamicContext::Ptr &context) const; + QRegExp pattern(const DynamicContext::Ptr &context) const; /** * @returns the number of captures, also called parenthesized sub-expressions, the pattern has. diff --git a/src/xmlpatterns/parser/qquerytransformparser.cpp b/src/xmlpatterns/parser/qquerytransformparser.cpp index 25821ca..781b899 100644 --- a/src/xmlpatterns/parser/qquerytransformparser.cpp +++ b/src/xmlpatterns/parser/qquerytransformparser.cpp @@ -3735,7 +3735,7 @@ yyreduce: /* Line 1269 of yacc.c. */ #line 1412 "querytransformparser.ypp" { - const QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); + QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); if(!encNameRegExp.exactMatch((yyvsp[(2) - (2)].sval))) { diff --git a/src/xmlpatterns/parser/querytransformparser.ypp b/src/xmlpatterns/parser/querytransformparser.ypp index 1814f28..d69868e 100644 --- a/src/xmlpatterns/parser/querytransformparser.ypp +++ b/src/xmlpatterns/parser/querytransformparser.ypp @@ -1470,7 +1470,7 @@ VersionDecl: /* empty */ Encoding: /* empty */ /* [X] */ | ENCODING StringLiteral { - const QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); + QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); if(!encNameRegExp.exactMatch($2)) { diff --git a/src/xmlpatterns/schema/qxsdschemachecker.cpp b/src/xmlpatterns/schema/qxsdschemachecker.cpp index 0536fca..33e2679 100644 --- a/src/xmlpatterns/schema/qxsdschemachecker.cpp +++ b/src/xmlpatterns/schema/qxsdschemachecker.cpp @@ -1124,7 +1124,7 @@ void XsdSchemaChecker::checkConstrainingFacets(const XsdFacet::Hash &facets, con for (int i = 0; i < multiValue.count(); ++i) { const DerivedString<TypeString>::Ptr value = multiValue.at(i); - const QRegExp exp = PatternPlatform::parsePattern(value->stringValue(), m_context, &reflection); + QRegExp exp = PatternPlatform::parsePattern(value->stringValue(), m_context, &reflection); if (!exp.isValid()) { m_context->error(QtXmlPatterns::tr("%1 facet contains invalid regular expression").arg(formatKeyword("pattern.")), XsdSchemaContext::XSDError, sourceLocation(simpleType)); return; diff --git a/src/xmlpatterns/schema/qxsdschemaparser.cpp b/src/xmlpatterns/schema/qxsdschemaparser.cpp index a00b77e..292886e 100644 --- a/src/xmlpatterns/schema/qxsdschemaparser.cpp +++ b/src/xmlpatterns/schema/qxsdschemaparser.cpp @@ -511,7 +511,7 @@ void XsdSchemaParser::parseSchema(ParserType parserType) if (hasAttribute(CommonNamespaces::XML, QString::fromLatin1("lang"))) { const QString value = readAttribute(QString::fromLatin1("lang"), CommonNamespaces::XML); - const QRegExp exp(QString::fromLatin1("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")); + QRegExp exp(QString::fromLatin1("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")); if (!exp.exactMatch(value)) { attributeContentError("xml:lang", "schema", value); return; @@ -1286,7 +1286,7 @@ XsdDocumentation::Ptr XsdSchemaParser::parseDocumentation() if (hasAttribute(CommonNamespaces::XML, QString::fromLatin1("lang"))) { const QString value = readAttribute(QString::fromLatin1("lang"), CommonNamespaces::XML); - const QRegExp exp(QString::fromLatin1("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")); + QRegExp exp(QString::fromLatin1("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")); if (!exp.exactMatch(value)) { attributeContentError("xml:lang", "documentation", value); return documentation; diff --git a/src/xmlpatterns/schema/qxsdtypechecker.cpp b/src/xmlpatterns/schema/qxsdtypechecker.cpp index e0ce55b..af09816 100644 --- a/src/xmlpatterns/schema/qxsdtypechecker.cpp +++ b/src/xmlpatterns/schema/qxsdtypechecker.cpp @@ -452,7 +452,7 @@ bool XsdTypeChecker::checkConstrainingFacetsString(const QString &value, const X bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(value)) { found = true; break; @@ -547,7 +547,7 @@ bool XsdTypeChecker::checkConstrainingFacetsSignedInteger(long long value, const bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -633,7 +633,7 @@ bool XsdTypeChecker::checkConstrainingFacetsUnsignedInteger(unsigned long long v bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -719,7 +719,7 @@ bool XsdTypeChecker::checkConstrainingFacetsDouble(double value, const QString & bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -820,7 +820,7 @@ bool XsdTypeChecker::checkConstrainingFacetsDateTime(const QDateTime &value, con bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -898,7 +898,7 @@ bool XsdTypeChecker::checkConstrainingFacetsDuration(const AtomicValue::Ptr&, co bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -925,7 +925,7 @@ bool XsdTypeChecker::checkConstrainingFacetsBoolean(bool, const QString &lexical bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -1038,7 +1038,7 @@ bool XsdTypeChecker::checkConstrainingFacetsQName(const QXmlName &value, const Q bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -1215,7 +1215,7 @@ bool XsdTypeChecker::checkConstrainingFacetsList(const QStringList &values, cons bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; @@ -1272,7 +1272,7 @@ bool XsdTypeChecker::checkConstrainingFacetsUnion(const QString &value, const QS bool found = false; for (int j = 0; j < multiValue.count(); ++j) { const QString pattern = multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(); - const QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); + QRegExp exp = PatternPlatform::parsePattern(pattern, m_context, m_reflection); if (exp.exactMatch(lexicalValue)) { found = true; break; diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index 372bcdb..1b5d424 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -1728,7 +1728,7 @@ void tst_QXmlQuery::messageXML() const query.setQuery(QLatin1String("1basicSyntaxError")); - const QRegExp removeFilename(QLatin1String("Location: file:.*\\#")); + QRegExp removeFilename(QLatin1String("Location: file:.*\\#")); QVERIFY(removeFilename.isValid()); QVERIFY(messageValidator.success()); diff --git a/tests/auto/xmlpatterns/tst_xmlpatterns.cpp b/tests/auto/xmlpatterns/tst_xmlpatterns.cpp index abae5d8..29efbe4 100644 --- a/tests/auto/xmlpatterns/tst_xmlpatterns.cpp +++ b/tests/auto/xmlpatterns/tst_xmlpatterns.cpp @@ -182,7 +182,7 @@ void tst_XmlPatterns::xquerySupport() { /* There's a wide range of different version strings used. For * instance, "4.4.0-rc1". */ - const QRegExp removeVersion(QLatin1String(" Qt \\d\\.\\d.*")); + QRegExp removeVersion(QLatin1String(" Qt \\d\\.\\d.*")); QVERIFY(removeVersion.isValid()); QCOMPARE(QString(fixedStderr).remove(removeVersion) + QChar('|'), rawExpectedStdErr + QChar('|')); } diff --git a/tools/xmlpatterns/qapplicationargumentparser.cpp b/tools/xmlpatterns/qapplicationargumentparser.cpp index 62bd3e2..008d905 100644 --- a/tools/xmlpatterns/qapplicationargumentparser.cpp +++ b/tools/xmlpatterns/qapplicationargumentparser.cpp @@ -824,7 +824,7 @@ QVariant QApplicationArgumentParser::convertToValue(const QApplicationArgument & } case QVariant::RegExp: { - const QRegExp exp(input); + QRegExp exp(input); if(exp.isValid()) return QVariant(exp); |