Skip to content

[BUG] function supplied to fn:filter must return xs:booleanΒ #3382

@line-o

Description

@line-o

Describe the bug

eXistDB does not enforce the return type of the user provided filter function.

Relevant spec:

https://www.w3.org/TR/xpath-functions/#func-filter

especially,

there is no special treatment for numeric predicate values, and no conversion to an effective boolean value

Expected behavior

Return types of function parameter to fn:filter other than xs:boolean must throw XPTY0004.

To Reproduce

xquery version "3.1";

module namespace hofs="http://exist-db.org/xquery/test/higher-order-functions";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare
    %test:assertError("XPTY0004")
function hofs:function-has-wrong-return-type () {
    filter((0 to 1), function ($a) { $a })
};

declare
    %test:assertError("XPTY0004")
function hofs:return-mixed-types () {
    filter((true(), false(), 1, ""), function ($a) { $a })
};

Context (please always complete the following information):

  • OS: macOSX 10.15.4
  • eXist-db version: since the feature was released in 2.2 until latest HEAD (5.3.0-SNAPSHOT)
  • Java Version 8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugissue confirmed as bugdeprecationxqueryissue is related to xquery implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions