Open joewiz opened 3 years ago
I'm associating this issue with eXist 6 as the fix would likely break code depending on the current buggy behavior.
I've extended the report to include fn:starts-with()
and fn:ends-with()
- which suffer from the same bug in eXist.
I've extended the report to include fn:matches()
, fn:replace()
and fn:analyze-string()
.
I've extended the report to include every function in the fn:
namespace that takes any xs:string
parameter, the XQSuite results. After completing this more exhaustive test, the functions with the problem described above are:
fn:contains()
fn:starts-with()
fn:ends-with()
fn:matches()
fn:replace()
fn:tokenize()
Whoa! What a find @joewiz
Fixing this has the potential to break some applications and even libraries written for exist-db
Describe the bug
eXist's implementation of numerous functions that perform operations on string values, such as
fn:contains()
,fn:starts-with()
,fn:ends-with()
,fn:matches()
,fn:replace()
, andfn:tokenize()
, is mishandling inputs, allowing non-string types instead of raising errors about the invalid data types.Taking
fn:contains()
for instance, the XQuery spec states that this function takes two parameters, bothxs:string?
. See https://www.w3.org/TR/xpath-functions-31/#func-contains. In the 1st example below, rules of Type Promotion do not allow promoting numbers like1
to strings like"1"
. And given the signature of the function, there is no reason eXist should try to cast any of the parameters asxs:double
, as it is doing in the 2nd example.Expected behavior
contains("foo", 1)
should raise an XPTY0004 type error that the 2nd argument must be of typexs:string
(and does so in Saxon and BaseX), but eXist returnsfalse()
.contains(<foo>bar</foo>, 1)
should raise the same type error about the 2nd argument not being of typexs:string
(and does so in Saxon and BaseX), but eXist returns an error about the 1st argument not being castable toxs:double
.Same goes for the other standard functions that take strings, like
fn:starts-with()
,fn:ends-with()
,fn:matches()
,fn:replace()
, andfn:tokenize()
.To Reproduce
The following XQSuite test module contains variations of the above examples for
fn:contains()
and shows the failure described above. Same forfn:starts-with()
,fn:ends-with()
,fn:matches()
,fn:replace()
, andfn:tokenize()
.Every other standard function from the
fn:
namespace that takes a parameter of typexs:string
correctly raises the XPTY0004 error.This test returns the following results:
Context (please always complete the following information):
Additional context
conf.xml
? n/a