You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Manoj Mokashi (JIRA)" <ji...@apache.org> on 2012/06/29 13:01:45 UTC
[jira] [Created] (JEXL-134) Issue with evaluation of concat of
variables : \r + \n gives 0
Manoj Mokashi created JEXL-134:
----------------------------------
Summary: Issue with evaluation of concat of variables : \r + \n gives 0
Key: JEXL-134
URL: https://issues.apache.org/jira/browse/JEXL-134
Project: Commons JEXL
Issue Type: Bug
Affects Versions: 2.1.1
Environment: Windows Xp, jdk1.6.0_14
Reporter: Manoj Mokashi
Consider the following example :
String jexlExp = "$$__INPUT + nl";
Expression e = jexl.createExpression( jexlExp );
// Create a context and add data
JexlContext jc = new MapContext();
jc.set("$$__INPUT", "\r" );
jc.set("nl", "\n");
// Now evaluate the expression, getting the result
Object o = e.evaluate(jc);
The result is 0 instead of "\r\n"
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (JEXL-134) Issue with evaluation of concat of
variables : \r + \n gives 0
Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JEXL-134?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Biestro updated JEXL-134:
-------------------------------
Fix Version/s: 2.1.2
> Issue with evaluation of concat of variables : \r + \n gives 0
> --------------------------------------------------------------
>
> Key: JEXL-134
> URL: https://issues.apache.org/jira/browse/JEXL-134
> Project: Commons JEXL
> Issue Type: Bug
> Affects Versions: 2.1.1
> Environment: Windows Xp, jdk1.6.0_14
> Reporter: Manoj Mokashi
> Assignee: Henri Biestro
> Fix For: 2.1.2
>
>
> Consider the following example :
> String jexlExp = "$$__INPUT + nl";
> Expression e = jexl.createExpression( jexlExp );
> // Create a context and add data
> JexlContext jc = new MapContext();
> jc.set("$$__INPUT", "\r" );
> jc.set("nl", "\n");
> // Now evaluate the expression, getting the result
> Object o = e.evaluate(jc);
> The result is 0 instead of "\r\n"
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (JEXL-134) Issue with evaluation of concat of
variables : \r + \n gives 0
Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JEXL-134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13404738#comment-13404738 ]
Henri Biestro commented on JEXL-134:
------------------------------------
Thanks for the bug report.
The culprit is the usage of trim in JexlArithemtic coercion methods toDouble and toBigDecimal which, in this case, will treat strings as empty and allow coercion to 0.
As a workaround, till 2.1.2 is released, you can derive JexlArithmetic and override the add method to treat String arguments early as in the following example.
Hope this helps.
{code}
public static class Arithmetic134 extends JexlArithmetic {
public Arithmetic134() {
super(false);
}
@Override
public Object add(Object lhs, Object rhs) {
if (lhs instanceof String && rhs instanceof String) {
return ((String) lhs) + ((String) rhs);
} else {
return super.add(lhs, rhs);
}
}
}
@Test
public void test134() throws Exception {
JexlEngine jexl = new JexlEngine(null, new Arithmetic134(), null, null);
String jexlExp = "$$__INPUT + nl";
Expression e = jexl.createExpression( jexlExp );
// Create a context and add data
JexlContext jc = new MapContext();
jc.set("$$__INPUT", "\r" );
jc.set("nl", "\n");
// Now evaluate the expression, getting the result
Object o = e.evaluate(jc);
assertEquals("\r\n", o);
}
{code}
> Issue with evaluation of concat of variables : \r + \n gives 0
> --------------------------------------------------------------
>
> Key: JEXL-134
> URL: https://issues.apache.org/jira/browse/JEXL-134
> Project: Commons JEXL
> Issue Type: Bug
> Affects Versions: 2.1.1
> Environment: Windows Xp, jdk1.6.0_14
> Reporter: Manoj Mokashi
> Assignee: Henri Biestro
> Fix For: 2.1.2
>
>
> Consider the following example :
> String jexlExp = "$$__INPUT + nl";
> Expression e = jexl.createExpression( jexlExp );
> // Create a context and add data
> JexlContext jc = new MapContext();
> jc.set("$$__INPUT", "\r" );
> jc.set("nl", "\n");
> // Now evaluate the expression, getting the result
> Object o = e.evaluate(jc);
> The result is 0 instead of "\r\n"
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (JEXL-134) Issue with evaluation of concat of
variables : \r + \n gives 0
Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JEXL-134?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Biestro resolved JEXL-134.
--------------------------------
Resolution: Fixed
Fix by removing occurrences of trim in JexlArithmetic coercions
src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
src/test/java/org/apache/commons/jexl2/IssuesTest.java
Committed revision 1355930.
> Issue with evaluation of concat of variables : \r + \n gives 0
> --------------------------------------------------------------
>
> Key: JEXL-134
> URL: https://issues.apache.org/jira/browse/JEXL-134
> Project: Commons JEXL
> Issue Type: Bug
> Affects Versions: 2.1.1
> Environment: Windows Xp, jdk1.6.0_14
> Reporter: Manoj Mokashi
> Assignee: Henri Biestro
> Fix For: 2.1.2
>
>
> Consider the following example :
> String jexlExp = "$$__INPUT + nl";
> Expression e = jexl.createExpression( jexlExp );
> // Create a context and add data
> JexlContext jc = new MapContext();
> jc.set("$$__INPUT", "\r" );
> jc.set("nl", "\n");
> // Now evaluate the expression, getting the result
> Object o = e.evaluate(jc);
> The result is 0 instead of "\r\n"
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (JEXL-134) Issue with evaluation of concat of
variables : \r + \n gives 0
Posted by "Manoj Mokashi (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JEXL-134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13404897#comment-13404897 ]
Manoj Mokashi commented on JEXL-134:
------------------------------------
Hi Henri, thanks for the quick resolution :)
> Issue with evaluation of concat of variables : \r + \n gives 0
> --------------------------------------------------------------
>
> Key: JEXL-134
> URL: https://issues.apache.org/jira/browse/JEXL-134
> Project: Commons JEXL
> Issue Type: Bug
> Affects Versions: 2.1.1
> Environment: Windows Xp, jdk1.6.0_14
> Reporter: Manoj Mokashi
> Assignee: Henri Biestro
> Fix For: 2.1.2
>
>
> Consider the following example :
> String jexlExp = "$$__INPUT + nl";
> Expression e = jexl.createExpression( jexlExp );
> // Create a context and add data
> JexlContext jc = new MapContext();
> jc.set("$$__INPUT", "\r" );
> jc.set("nl", "\n");
> // Now evaluate the expression, getting the result
> Object o = e.evaluate(jc);
> The result is 0 instead of "\r\n"
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira