You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mike Bartlett (Jira)" <ji...@apache.org> on 2019/09/18 16:32:00 UTC

[jira] [Created] (JEXL-315) JxltEngine literal string strings ending in \ $ or # throw JxltEngine$Exception

Mike Bartlett created JEXL-315:
----------------------------------

             Summary: JxltEngine literal string strings ending in \ $ or # throw JxltEngine$Exception
                 Key: JEXL-315
                 URL: https://issues.apache.org/jira/browse/JEXL-315
             Project: Commons JEXL
          Issue Type: Bug
    Affects Versions: 3.1
            Reporter: Mike Bartlett


When parsing literal strings with the JxltEngine, if the string ends with \ $ or # a JxltEngine$Exception is thrown. Escaping the ending character works, but seems an unnecessary burden on the user.

Example:

JxltEngine jxltEngine = (new JexlBuilder()).create().createJxltEngine();
 Expression exp = jxltEngine.createExpression("Testing$");
 Object value = exp.evaluate(new MapContext());

Stack Trace:

org.apache.commons.jexl3.JxltEngine$Exception: com.openmarket.workflow.el.ElEngineTest.testBug@40 failed to parse 'Testing$'org.apache.commons.jexl3.JxltEngine$Exception: com.openmarket.workflow.el.ElEngineTest.testBug@40 failed to parse 'Testing$' at org.apache.commons.jexl3.internal.TemplateEngine.createExpression(TemplateEngine.java:668) at org.apache.commons.jexl3.JxltEngine.createExpression(JxltEngine.java:217) at com.openmarket.workflow.el.ElEngineTest.testBug(ElEngineTest.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)Caused by: org.apache.commons.jexl3.JxltEngine$Exception: com.openmarket.workflow.el.ElEngineTest.testBug@40 malformed expression: Testing$ at org.apache.commons.jexl3.internal.TemplateEngine.parseExpression(TemplateEngine.java:886) at org.apache.commons.jexl3.internal.TemplateEngine.createExpression(TemplateEngine.java:664) ... 25 more

 

Simple Fix in the code:

org.apache.commons.jexl3.internal.TemplateEngine

In method:
{quote}{{TemplateExpression parseExpression(JexlInfo info, String expr, Scope scope) { // CSOFF: MethodLength}}

 

{{for (int column = 0; column < size; ++column) {}}

{{  ...}}

{{}}}

{{// Add this code at the end of the for loop to h}}{{andle strings ending in \, # or $}}
{{ if (state == ParseState.ESCAPE) {}}

{{    strb.append('\\');}}

{{    state = ParseState.CONST;}}
{{ } else if (state == ParseState.DEFERRED0) {}}
{{    strb.append(deferredChar);}}
{{    state = ParseState.CONST;}}
{{ } else if (state == ParseState.IMMEDIATE0) {}}
{{    strb.append(immediateChar);}}
{{    state = ParseState.CONST;}}
{{ }}}

{{...}}
{quote}
 

 

 

 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)