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

Quote escaping cannot be escaped

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.0.1
    • None
    • All Java

    Description

      I want to invoke a "replace" method which (pretty much like String.replace()) takes three String parameters:

      function.replace(String text, String oldPart, String newPart)

      If I invoke it to replace single backslash characters with double backslash characters (which is admittedly a VERY special use case), I invoke it in my unit test with an expression like this one:

      function.replace('DOMAIN\somename', '
      ', '\\\\')

      The result with JEXL 1.x was a string "DOMAIN
      somename". But with JEXL 2, I get this error:

      2010-03-11 14:50:59,681 [CC:] [RC:] [CN:] - [SYSTEM] [INVALID_EXPR] Invalid expression in configuration. Expression: 'function.replace('DOMAIN\myname', '
      ', '\\\\') / Exception: org.apache.commons.jexl2.JexlException: com.usp.sls.toolkit.expression.impl.Jexl2Provider.getScript@441tokenization failed'
      org.apache.commons.jexl2.JexlException: com.usp.sls.toolkit.expression.impl.Jexl2Provider.getScript@441tokenization failed
      at org.apache.commons.jexl2.JexlEngine.parse(JexlEngine.java:816)
      at org.apache.commons.jexl2.JexlEngine.createScript(JexlEngine.java:414)
      at org.apache.commons.jexl2.JexlEngine.createScript(JexlEngine.java:397)
      at com.usp.sls.toolkit.expression.impl.Jexl2Provider.getScript(Jexl2Provider.java:441)
      at com.usp.sls.toolkit.expression.impl.Jexl2Provider.evaluateExpression(Jexl2Provider.java:152)
      at com.usp.sls.toolkit.expression.Expression.evaluateExpression(Expression.java:201)
      at com.usp.sls.toolkit.expression.JexlTest.testReplace(JexlTest.java:84)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at junit.framework.TestCase.runTest(TestCase.java:164)
      at junit.framework.TestCase.runBare(TestCase.java:130)
      at junit.framework.TestResult$1.protect(TestResult.java:110)
      at junit.framework.TestResult.runProtected(TestResult.java:128)
      at junit.framework.TestResult.run(TestResult.java:113)
      at junit.framework.TestCase.run(TestCase.java:120)
      at junit.framework.TestSuite.runTest(TestSuite.java:228)
      at junit.framework.TestSuite.run(TestSuite.java:223)
      at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: org.apache.commons.jexl2.parser.TokenMgrError: Lexical error at line 1, column 42. Encountered: "
      " (92), after : ""
      at org.apache.commons.jexl2.parser.ParserTokenManager.getNextToken(ParserTokenManager.java:1564)
      at org.apache.commons.jexl2.parser.Parser.jj_scan_token(Parser.java:3914)
      at org.apache.commons.jexl2.parser.Parser.jj_3R_118(Parser.java:2776)
      at org.apache.commons.jexl2.parser.Parser.jj_3R_111(Parser.java:2759)

      Obviously, the JEXL parser thinks that the backslash in the first string is meant to escape the following quote, which it isn't. The String should actually end there. So, I tried to escape the escape character, like this:

      function.replace('DOMAIN\somename', '\\\\', '\\\\\\\\')

      But to no avail, same error.

      So, can escape characters be escaped in JEXL 2?

      Attachments

        Activity

          People

            henrib Henri Biestro
            marcelschoen Marcel Schoen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: