Skip to content

Commit 1a5e147

Browse files
committed
Merge branch 'develop' of github.com:eXist-db/exist into feature/add_function_document-uri0
* 'develop' of github.com:eXist-db/exist: [test] Added test supplied by @joewiz [bugfix] Make sure the correct context sequence is used with util:eval-with-context Closes #3039
2 parents 9c3b969 + 89c6975 commit 1a5e147

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,30 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
9898
// get statically known documents from the context
9999
DocumentSet ds = context.getStaticallyKnownDocuments();
100100
if (ds == null || ds.getDocumentCount() == 0) {return Sequence.EMPTY_SEQUENCE;}
101-
101+
102+
// fix for util:eval-with-context
103+
if (contextSequence != null) {
104+
if (!contextSequence.isEmpty()) {
105+
final Item item = contextSequence.itemAt(0);
106+
// context item must be a node
107+
if (!Type.subTypeOf(item.getType(), Type.NODE)) {
108+
throw new XPathException(this, ErrorCodes.XPTY0020, "Context item is not a node");
109+
}
110+
final NodeValue node = (NodeValue)item;
111+
// return fn:root(self::node()) treat as document-node()
112+
if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
113+
return new NodeProxy(((NodeProxy)item).getOwnerDocument());
114+
} else {
115+
if (node.getType() == Type.DOCUMENT) {
116+
return node;
117+
}
118+
return (org.exist.dom.memtree.DocumentImpl) node.getOwnerDocument();
119+
}
120+
} else {
121+
return Sequence.EMPTY_SEQUENCE;
122+
}
123+
}
124+
102125
// // if the expression occurs in a nested context, we might have cached the
103126
// // document set
104127
// // TODO: disabled cache for now as it may cause concurrency issues

exist-core/src/test/java/org/exist/storage/ShutdownTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void storeAndShutdown() throws EXistException, PermissionDeniedException,
9090

9191
final XQuery xquery = pool.getXQueryService();
9292
assertNotNull(xquery);
93-
final Sequence result = xquery.execute(broker, "//SPEECH[contains(LINE, 'love')]", Sequence.EMPTY_SEQUENCE);
93+
final Sequence result = xquery.execute(broker, "//SPEECH[contains(LINE, 'love')]", null);
9494
assertNotNull(result);
9595
assertEquals(187, result.getItemCount());
9696

exist-core/src/test/xquery/util/eval-with-context.xql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ function ut:timeout() {
3434
</static-context>
3535
return
3636
util:eval-with-context("util:wait(2), <ok/>", $context, false() )
37-
};
37+
};
38+
39+
declare
40+
%test:assertEquals(1)
41+
function ut:root-node() {
42+
util:eval-with-context('count(/)', (), false(), document { <x/> })
43+
};

0 commit comments

Comments
 (0)