Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException

if (value.isPresent()) {
value.get().analyze(contextInfo);
if (!value.get().getCardinality().atMostOne()) {
throw new XPathException(this, ErrorCodes.XPTY0004, "The context item must be exactly one item");
}

}
}

Expand All @@ -77,6 +81,14 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
}
} else {
return value.get().eval(null, null);

// else {
// final Sequence result = value.get().eval(null, null);
// if (result.isEmpty() || result.hasMany()){
// throw new XPathException(this, ErrorCodes.XPTY0004,"The context item must be exactly one item");
// } else {
// return result;
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
import java.util.Optional;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;

/**
* Tests for XQuery 3.0's declare context item
Expand Down Expand Up @@ -144,6 +143,22 @@ public void declareContextItem() throws EXistException, PermissionDeniedExceptio
}
}

@Test
public void declareContextItemMoreThanOneItem() throws EXistException, PermissionDeniedException, XPathException, IOException {
final String query =
"xquery version \"3.0\";\n" +
"declare context item := (1,2); \n" +
".";

final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.getBroker();
final XQueryUtil.QueryResult queryResult = XQueryUtil.query(broker, new StringSource(query), false, null, null, null, null, null)) {
fail("Expected XQuery error XPTY0004");
} catch (final XPathException e){
assertEquals(ErrorCodes.XPTY0004, e.getErrorCode());
}
}

/**
* See issue https://github.com/eXist-db/exist/issues/2156
*/
Expand Down
Loading