Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-315

JxltEngine literal string strings ending in \ $ or # throw JxltEngine$Exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None

    Description

      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:

      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 handle 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;
      {{ }}}

      ...

       

       

       

       

       

      Attachments

        Activity

          People

            henrib Henri Biestro
            mbartlett Mike Bartlett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: