Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ForClause PositionalVar empty sequence handling #5589

Merged
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
3 changes: 2 additions & 1 deletion exist-core/src/main/java/org/exist/xquery/ForExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ private void processItem(LocalVariable var, Item contextItem, Sequence in, Seque
context.proceed(this);
context.setContextSequencePosition(p, in);
if (positionalVariable != null) {
at.setValue(new IntegerValue(this, p + 1));
final int position = contextItem == AtomicValue.EMPTY_VALUE ? 0 : p + 1;
at.setValue(new IntegerValue(this, position));
}
final Sequence contextSequence = contextItem.toSequence();
// set variable value to current item
Expand Down
29 changes: 29 additions & 0 deletions exist-core/src/test/xquery/xquery3/flwor.xql
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,32 @@ function flwor:allowing-empty($n as xs:integer) {
return concat("[", $x, "]")
};

declare
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that shows the correct behaviour if allowing empty is not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't any right now
Should I add them?

%test:args(4)
%test:assertEquals(":0")
%test:args(2)
%test:assertEquals("b:1")
%test:args(1)
%test:assertEquals("a:1")
%test:args(5)
%test:assertEquals(":0")
function flwor:allowing-empty-fix($n as xs:integer) {
let $sequence := ("a", "b", "c")[$n]
for $x allowing empty at $y in $sequence
return $x || ":" || $y
};

declare
%test:args(4)
%test:assertEquals("")
%test:args(2)
%test:assertEquals("b:1")
function flwor:no-allow-empty($n as xs:integer) {
let $sequence := ("a", "b", "c")[$n]
return
if (empty($sequence)) then
""
else
for $x at $y in $sequence
return $x || ":" || $y
};
Loading