commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markos Fragkakis <markos.fragka...@gmail.com>
Subject [jxpath] Evaluation of the comparison '' = 0
Date Tue, 13 Dec 2011 10:28:37 GMT
Hi all,

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 [1] 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 <http://www.w3.org/TR/xpath/#function-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<http://www.w3.org/TR/xpath/#function-number>
* function. Otherwise, both objects to be compared are converted to strings
as if by applying the *string
<http://www.w3.org/TR/xpath/#function-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]<http://www.w3.org/TR/xpath/#IEEE754>.
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?

Cheers,

Markos

[1] http://www.w3.org/TR/xpath/#section-Expressions

-- 
Sent from my iPhone

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message