From d17eba9d34f412e592c3b049c6c14fd9ccada87b Mon Sep 17 00:00:00 2001 From: "David E. Narvaez" Date: Sun, 21 Jun 2015 22:24:39 -0400 Subject: Iterate Over the Items (Not the Operands) of a Literal Sequence The current code iterates over the (empty) list of operands of a Literal Sequence, ignoring any items in it, so Literal Sequences are always ignored in the ExpressionSequence. Task-number: QTBUG-35897 Change-Id: I60341ac21c8e3b77bf6d8dfeebdbafe010844406 Reviewed-by: Erik Verbruggen --- src/xmlpatterns/expr/qexpression_p.h | 7 ++++++- src/xmlpatterns/expr/qexpressionsequence.cpp | 9 +++++++++ src/xmlpatterns/expr/qliteralsequence.cpp | 2 +- tests/auto/qxmlquery/tst_qxmlquery.cpp | 2 +- tests/auto/xmlpatterns/queries/literalsequence.xq | 1 + .../xmlpatterns/stderrBaselines/QTBUG35897literalsequence.txt | 0 tests/auto/xmlpatterns/tst_xmlpatterns.cpp | 7 +++++++ 7 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/auto/xmlpatterns/queries/literalsequence.xq create mode 100644 tests/auto/xmlpatterns/stderrBaselines/QTBUG35897literalsequence.txt diff --git a/src/xmlpatterns/expr/qexpression_p.h b/src/xmlpatterns/expr/qexpression_p.h index c799725..7a7899f 100644 --- a/src/xmlpatterns/expr/qexpression_p.h +++ b/src/xmlpatterns/expr/qexpression_p.h @@ -375,10 +375,15 @@ namespace QPatternist IDExistsFN, /** - * Identifies ExpressionSequence and LiteralSequence. + * Identifies ExpressionSequence. */ IDExpressionSequence, + /** + * Identifies LiteralSequence. + */ + IDLiteralSequence, + /** * Identifies GeneralComparison. */ diff --git a/src/xmlpatterns/expr/qexpressionsequence.cpp b/src/xmlpatterns/expr/qexpressionsequence.cpp index 4ff8082..c71beb9 100644 --- a/src/xmlpatterns/expr/qexpressionsequence.cpp +++ b/src/xmlpatterns/expr/qexpressionsequence.cpp @@ -34,6 +34,8 @@ #include "qcardinalityverifier_p.h" #include "qcommonsequencetypes_p.h" #include "qemptysequence_p.h" +#include "qabstractxmlforwarditerator_p.h" +#include "qliteral_p.h" #include "qsequencemappingiterator_p.h" #include "qexpressionsequence_p.h" @@ -106,6 +108,13 @@ Expression::Ptr ExpressionSequence::compress(const StaticContext::Ptr &context) for(; seqIt != seqEnd; ++seqIt) result.append(*seqIt); + } else if (Id == IDLiteralSequence) { + /* Rewrite "(1, (2, 3), 4)" into "(1, 2, 3, 4)" */ + // Note: LiteralSequence does not use the dynamic context, so we pass in a nullptr. + Item::Iterator::Ptr seqIt = (*it)->evaluateSequence(DynamicContext::Ptr(Q_NULLPTR)); + + while (!seqIt->next().isNull()) + result.append(Literal::Ptr(new Literal(seqIt->current()))); } else result.append(*it); diff --git a/src/xmlpatterns/expr/qliteralsequence.cpp b/src/xmlpatterns/expr/qliteralsequence.cpp index e0b610d..8c920d3 100644 --- a/src/xmlpatterns/expr/qliteralsequence.cpp +++ b/src/xmlpatterns/expr/qliteralsequence.cpp @@ -73,7 +73,7 @@ ExpressionVisitorResult::Ptr LiteralSequence::accept(const ExpressionVisitor::Pt Expression::ID LiteralSequence::id() const { - return IDExpressionSequence; + return IDLiteralSequence; } Expression::Properties LiteralSequence::properties() const diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index 3350911..cc2cb13 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -231,7 +231,7 @@ private: /** * One excluded, since we skip static-base-uri.xq. */ - ExpectedQueryCount = 29 + ExpectedQueryCount = 30 }; static void checkBaseURI(const QUrl &baseURI, const QString &candidate); diff --git a/tests/auto/xmlpatterns/queries/literalsequence.xq b/tests/auto/xmlpatterns/queries/literalsequence.xq new file mode 100644 index 0000000..3420df0 --- /dev/null +++ b/tests/auto/xmlpatterns/queries/literalsequence.xq @@ -0,0 +1 @@ +("someString", tokenize("a,b",",")) diff --git a/tests/auto/xmlpatterns/stderrBaselines/QTBUG35897literalsequence.txt b/tests/auto/xmlpatterns/stderrBaselines/QTBUG35897literalsequence.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/xmlpatterns/tst_xmlpatterns.cpp b/tests/auto/xmlpatterns/tst_xmlpatterns.cpp index 85dc50a..ffb1697 100644 --- a/tests/auto/xmlpatterns/tst_xmlpatterns.cpp +++ b/tests/auto/xmlpatterns/tst_xmlpatterns.cpp @@ -757,6 +757,13 @@ void tst_XmlPatterns::xquerySupport_data() const << QString() << QString(); + QTest::newRow("QTBUG-35897: literal sequence") + << 0 + << QByteArray("someString a b\n") + << QStringList((path + QStringLiteral("literalsequence.xq"))) + << QString() + << QString(); + // TODO https? // TODO pass external variables that allows space around the equal sign. // TODO run fn:trace() -- cgit v1.2.1