You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Peter Verthez (Jira)" <ji...@apache.org> on 2020/02/27 10:28:00 UTC
[jira] [Updated] (JXPATH-197) number() function does not work
correctly on empty string
[ https://issues.apache.org/jira/browse/JXPATH-197?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Peter Verthez updated JXPATH-197:
---------------------------------
Description:
If you evaluate an expression that amounts to '' = 0 (comparison of empty string with 0), then JXPath is returning true for that although it should be false in my interpretation.
Analysis:
* when comparing a string with a number, a conversion is done: 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 ([https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans])
* the number function converts an empty string to a NaN number ([https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Number-Functions])
I see that in the InfoSetUtil class the following is implemented:
{code:java}
public static double doubleValue(Object object) {
...
if (object instanceof String) {
if (object.equals("")) {
return 0.0;
}
...
{code}
This is the cause of this problem, instead of 0.0 NaN should be returned.
was:
If you evaluate an expression that amounts to '' = 0, then JXPath is returning true for that although it should be false in my interpretation.
Analysis:
* when comparing a string with a number, a conversion is done: 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 ([https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans])
* the number function converts an empty string to a NaN number ([https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Number-Functions])
I see that in the InfoSetUtil class the following is implemented:
{code:java}
public static double doubleValue(Object object) {
...
if (object instanceof String) {
if (object.equals("")) {
return 0.0;
}
...
{code}
This is the cause of this problem, instead of 0.0 NaN should be returned.
> number() function does not work correctly on empty string
> ---------------------------------------------------------
>
> Key: JXPATH-197
> URL: https://issues.apache.org/jira/browse/JXPATH-197
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.3
> Reporter: Peter Verthez
> Priority: Major
>
> If you evaluate an expression that amounts to '' = 0 (comparison of empty string with 0), then JXPath is returning true for that although it should be false in my interpretation.
> Analysis:
> * when comparing a string with a number, a conversion is done: 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 ([https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans])
> * the number function converts an empty string to a NaN number ([https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Number-Functions])
> I see that in the InfoSetUtil class the following is implemented:
> {code:java}
> public static double doubleValue(Object object) {
> ...
> if (object instanceof String) {
> if (object.equals("")) {
> return 0.0;
> }
> ...
> {code}
> This is the cause of this problem, instead of 0.0 NaN should be returned.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)