I am evaluating the expression '' = 0 in JxPath 1.3, and I expect the result to be false. This is my code:
JXPathContext.newContext(ctaSectionABean).getValue("'' = 0");
However, the result returned to be is true! If I evaluate the same expression in Eclipse jxpath tool I get false, which I expect to be correct, since the documentation of xpath1.0 section 3.4 says the following:
When neither object to be compared is a node-set and the operator is =
or !=, then the objects are compared by converting them to a common
type as follows and then comparing them. If at least one object to be
compared is a boolean, then each object to be compared is converted to
a boolean as if by applying the boolean function. Otherwise, if at
least one object to be compared is a number, then each object to be
compared is converted to a number as if by applying the number
function. Otherwise, both objects to be compared are converted to
strings as if by applying the string function. The = comparison will
be true if and only if the objects are equal; the != comparison will
be true if and only if the objects are not equal. Numbers are compared
for equality according to IEEE 754 [IEEE 754]. Two booleans are equal
if either both are true or both are false. Two strings are equal if
and only if they consist of the same sequence of UCS characters.
So, since no object is a boolean and one of them is a number, I expect JxPath to try and convert them both to numbers. That would be 0 for 0 and NaN for '', and I tested that JxPath does convert them that way with the number() function. That means that JxPath does not try to convert them to numbers, as the spec defines.
Is this a bug?
Yes, if your information is correct then I think this is a bug.