Skip to content

Commit 97a8573

Browse files
committed
[bugfix] Update Predicate to handle the boolean correctly (#4810)
1 parent b951d8e commit 97a8573

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

exist-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@
767767
<include>src/test/java/org/exist/xquery/functions/xquery3/SerializeTest.java</include>
768768
<include>src/test/java/org/exist/xquery/value/DateTimeTypesTest.java</include>
769769
<include>src/test/xquery/emptySeq.xq</include>
770+
<include>src/test/xquery/startWithComp.xq</include>
770771
</includes>
771772
</licenseSet>
772773

@@ -1087,6 +1088,7 @@
10871088
<include>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</include>
10881089
<include>src/test/java/org/exist/xupdate/RemoveAppendTest.java</include>
10891090
<include>src/main/java/org/exist/xquery/GeneralComparison.java</include>
1091+
<include>src/main/java/org/exist/xquery/Predicate.java</include>
10901092
</includes>
10911093
</licenseSet>
10921094

@@ -1542,6 +1544,8 @@
15421544
<exclude>src/test/java/org/exist/xupdate/RemoveAppendTest.java</exclude>
15431545
<exclude>src/main/java/org/exist/xquery/GeneralComparison.java</exclude>
15441546
<exclude>src/test/xquery/emptySeq.xq</exclude>
1547+
<exclude>src/main/java/org/exist/xquery/Predicate.java</exclude>
1548+
<exclude>src/test/xquery/startWithComp.xq</exclude>
15451549
<!--
15461550
Derivative work licensed under dbXML 1.0 and LGPL 2.1
15471551
-->

exist-core/src/main/java/org/exist/xquery/Predicate.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -36,6 +60,7 @@
3660
import org.exist.xquery.value.SequenceIterator;
3761
import org.exist.xquery.value.Type;
3862
import org.exist.xquery.value.ValueSequence;
63+
import org.exist.xquery.value.BooleanValue;
3964

4065
import javax.annotation.Nullable;
4166
import java.util.Set;
@@ -377,7 +402,14 @@ private Sequence selectByNodeSet(final Sequence contextSequence) throws XPathExc
377402
final NodeSet contextSet = contextSequence.toNodeSet();
378403
final boolean contextIsVirtual = contextSet instanceof VirtualNodeSet;
379404
contextSet.setTrackMatches(false);
380-
final NodeSet nodes = super.eval(contextSet, null).toNodeSet();
405+
final Sequence res = super.eval(contextSet, null);
406+
if(!(res instanceof NodeSet)) {
407+
if(res == BooleanValue.FALSE)
408+
return NodeSet.EMPTY_SET;
409+
return res;
410+
}
411+
final NodeSet nodes = res.toNodeSet();
412+
381413
/*
382414
* if the predicate expression returns results from the cache we can
383415
* also return the cached result.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(:
2+
: Elemental
3+
: Copyright (C) 2024, Evolved Binary Ltd
4+
:
5+
6+
: https://www.evolvedbinary.com | https://www.elemental.xyz
7+
:
8+
: This library is free software; you can redistribute it and/or
9+
: modify it under the terms of the GNU Lesser General Public
10+
: License as published by the Free Software Foundation; version 2.1.
11+
:
12+
: This library is distributed in the hope that it will be useful,
13+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
: Lesser General Public License for more details.
16+
:
17+
: You should have received a copy of the GNU Lesser General Public
18+
: License along with this library; if not, write to the Free Software
19+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
:)
21+
xquery version "3.1";
22+
23+
module namespace t="http://exist-db.org/xquery/test";
24+
25+
declare namespace test="http://exist-db.org/xquery/xqsuite";
26+
27+
declare variable $t:XML := document {
28+
<Y1 id="1">
29+
<H1 id="2" a2="2">true</H1>
30+
</Y1>
31+
};
32+
33+
declare
34+
%test:setUp
35+
function t:setup() {
36+
let $testCol := xmldb:create-collection("/db", "test")
37+
return
38+
xmldb:store("/db/test", "test.xml", $t:XML)
39+
};
40+
41+
declare
42+
%test:tearDown
43+
function t:tearDown() {
44+
xmldb:remove("/db/test")
45+
};
46+
47+
declare
48+
%test:assertTrue
49+
function t:test() {
50+
doc("/db/test/test.xml")//*[starts-with(@a2, "1") = false()]
51+
=> exists()
52+
};

0 commit comments

Comments
 (0)