diff --git a/exist-core/pom.xml b/exist-core/pom.xml index ae4621cd59..578fe27005 100644 --- a/exist-core/pom.xml +++ b/exist-core/pom.xml @@ -766,6 +766,8 @@ src/test/java/org/exist/xquery/functions/xmldb/XMLDBStoreTest.java src/test/java/org/exist/xquery/functions/xquery3/SerializeTest.java src/test/java/org/exist/xquery/value/DateTimeTypesTest.java + src/test/xquery/emptySeq.xq + src/test/xquery/startWithComp.xq @@ -1085,6 +1087,8 @@ src/main/java/org/exist/xslt/EXistURIResolver.java src/main/java/org/exist/xslt/XsltURIResolverHelper.java src/test/java/org/exist/xupdate/RemoveAppendTest.java + src/main/java/org/exist/xquery/GeneralComparison.java + src/main/java/org/exist/xquery/Predicate.java @@ -1538,7 +1542,10 @@ src/main/java/org/exist/xslt/EXistURIResolver.java src/main/java/org/exist/xslt/XsltURIResolverHelper.java src/test/java/org/exist/xupdate/RemoveAppendTest.java - + src/main/java/org/exist/xquery/GeneralComparison.java + src/test/xquery/emptySeq.xq + src/main/java/org/exist/xquery/Predicate.java + src/test/xquery/startWithComp.xq diff --git a/exist-core/src/main/java/org/exist/xquery/GeneralComparison.java b/exist-core/src/main/java/org/exist/xquery/GeneralComparison.java index d277e81f75..15543010c3 100644 --- a/exist-core/src/main/java/org/exist/xquery/GeneralComparison.java +++ b/exist-core/src/main/java/org/exist/xquery/GeneralComparison.java @@ -1,4 +1,28 @@ /* + * Elemental + * Copyright (C) 2024, Evolved Binary Ltd + * + * admin@evolvedbinary.com + * https://www.evolvedbinary.com | https://www.elemental.xyz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * NOTE: Parts of this file contain code from 'The eXist-db Authors'. + * The original license header is included below. + * + * ===================================================================== + * * eXist-db Open Source Native XML Database * Copyright (C) 2001 The eXist-db Authors * @@ -648,6 +672,9 @@ protected Sequence nodeSetCompare( NodeSet nodes, Sequence contextSequence ) thr } } } + if (result.isEmpty()) { + return BooleanValue.FALSE; + } } if( context.getProfiler().traceFunctions() ) { diff --git a/exist-core/src/main/java/org/exist/xquery/Predicate.java b/exist-core/src/main/java/org/exist/xquery/Predicate.java index 986de11bb8..6877fb0fce 100644 --- a/exist-core/src/main/java/org/exist/xquery/Predicate.java +++ b/exist-core/src/main/java/org/exist/xquery/Predicate.java @@ -1,4 +1,28 @@ /* + * Elemental + * Copyright (C) 2024, Evolved Binary Ltd + * + * admin@evolvedbinary.com + * https://www.evolvedbinary.com | https://www.elemental.xyz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * NOTE: Parts of this file contain code from 'The eXist-db Authors'. + * The original license header is included below. + * + * ===================================================================== + * * eXist-db Open Source Native XML Database * Copyright (C) 2001 The eXist-db Authors * @@ -36,6 +60,7 @@ import org.exist.xquery.value.SequenceIterator; import org.exist.xquery.value.Type; import org.exist.xquery.value.ValueSequence; +import org.exist.xquery.value.BooleanValue; import javax.annotation.Nullable; import java.util.Set; @@ -377,7 +402,14 @@ private Sequence selectByNodeSet(final Sequence contextSequence) throws XPathExc final NodeSet contextSet = contextSequence.toNodeSet(); final boolean contextIsVirtual = contextSet instanceof VirtualNodeSet; contextSet.setTrackMatches(false); - final NodeSet nodes = super.eval(contextSet, null).toNodeSet(); + final Sequence res = super.eval(contextSet, null); + if(!(res instanceof NodeSet)) { + if(res == BooleanValue.FALSE) + return NodeSet.EMPTY_SET; + return res; + } + final NodeSet nodes = res.toNodeSet(); + /* * if the predicate expression returns results from the cache we can * also return the cached result. diff --git a/exist-core/src/test/xquery/emptySeq.xq b/exist-core/src/test/xquery/emptySeq.xq new file mode 100644 index 0000000000..3e3139e1c3 --- /dev/null +++ b/exist-core/src/test/xquery/emptySeq.xq @@ -0,0 +1,58 @@ +(: + : Elemental + : Copyright (C) 2024, Evolved Binary Ltd + : + : admin@evolvedbinary.com + : https://www.evolvedbinary.com | https://www.elemental.xyz + : + : This library is free software; you can redistribute it and/or + : modify it under the terms of the GNU Lesser General Public + : License as published by the Free Software Foundation; version 2.1. + : + : This library is distributed in the hope that it will be useful, + : but WITHOUT ANY WARRANTY; without even the implied warranty of + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + : Lesser General Public License for more details. + : + : You should have received a copy of the GNU Lesser General Public + : License along with this library; if not, write to the Free Software + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + :) +xquery version "3.1"; + +module namespace t="http://exist-db.org/xquery/test"; + +declare namespace test="http://exist-db.org/xquery/xqsuite"; + +declare variable $t:XML := document { + +}; + +declare + %test:setUp +function t:setup() { + xmldb:create-collection("/db", "test"), + xmldb:store("/db/test", "test.xml", $t:XML) +}; + +declare + %test:tearDown +function t:tearDown() { + xmldb:remove("/db/test") +}; + +declare + %test:assertTrue +function t:test-db() { + exists( + doc("/db/test/test.xml")//F[boolean(count(@id >= 2))] + ) +}; + +declare + %test:assertTrue +function t:test-mem() { + exists( + $t:XML//F[boolean(count(@id >= 2))] + ) +}; \ No newline at end of file diff --git a/exist-core/src/test/xquery/startWithComp.xq b/exist-core/src/test/xquery/startWithComp.xq new file mode 100644 index 0000000000..7d8e38c0e4 --- /dev/null +++ b/exist-core/src/test/xquery/startWithComp.xq @@ -0,0 +1,52 @@ +(: + : Elemental + : Copyright (C) 2024, Evolved Binary Ltd + : + : admin@evolvedbinary.com + : https://www.evolvedbinary.com | https://www.elemental.xyz + : + : This library is free software; you can redistribute it and/or + : modify it under the terms of the GNU Lesser General Public + : License as published by the Free Software Foundation; version 2.1. + : + : This library is distributed in the hope that it will be useful, + : but WITHOUT ANY WARRANTY; without even the implied warranty of + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + : Lesser General Public License for more details. + : + : You should have received a copy of the GNU Lesser General Public + : License along with this library; if not, write to the Free Software + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + :) +xquery version "3.1"; + +module namespace t="http://exist-db.org/xquery/test"; + +declare namespace test="http://exist-db.org/xquery/xqsuite"; + +declare variable $t:XML := document { + +

true

+
+}; + +declare + %test:setUp +function t:setup() { + let $testCol := xmldb:create-collection("/db", "test") + return + xmldb:store("/db/test", "test.xml", $t:XML) +}; + +declare + %test:tearDown +function t:tearDown() { + xmldb:remove("/db/test") +}; + +declare + %test:assertTrue +function t:test() { + doc("/db/test/test.xml")//*[starts-with(@a2, "1") = false()] + => exists() +}; \ No newline at end of file