You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2010/03/11 22:13:34 UTC
svn commit: r922023 - in /commons/proper/jexl/trunk/src:
main/java/org/apache/commons/jexl2/JexlException.java
main/java/org/apache/commons/jexl2/parser/Parser.jjt
test/java/org/apache/commons/jexl2/IssuesTest.java
Author: henrib
Date: Thu Mar 11 21:13:34 2010
New Revision: 922023
URL: http://svn.apache.org/viewvc?rev=922023&view=rev
Log:
Parser.jjt modified to allow proper escaping (backslash);
Added test for JEXL-98 & JEXL-97;
Added a formatting space in JexlException
Issue #JEXL-98 - Quote escaping cannot be escaped
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java?rev=922023&r1=922022&r2=922023&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java Thu Mar 11 21:13:34 2010
@@ -123,8 +123,9 @@ public class JexlException extends Runti
msg.append(dbg.end());
msg.append("]: '");
msg.append(dbg.data());
- msg.append("' ");
+ msg.append("'");
}
+ msg.append(' ');
msg.append(super.getMessage());
Throwable cause = getCause();
if (cause != null && NULL_OPERAND == cause.getMessage()) {
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt?rev=922023&r1=922022&r2=922023&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt Thu Mar 11 21:13:34 2010
@@ -556,9 +556,9 @@ void Reference() : {}
<*> TOKEN :
{
- <STRING_LITERAL :
- ("\"" ( ~["\"","\n","\r"] | "\\" ["u","n","t","b","r","f","\\","\""] )* "\"" )
- |
- ("\'" ( ~["\'","\n","\r"] | "\\" ["u","n","t","b","r","f","\\","\'"])* "\'" )
- >
+ < STRING_LITERAL:
+ "\"" (~["\"","\\","\n","\r","\u2028","\u2029"] | "\\" ~["\n","\r","\u2028","\u2029"])* "\""
+ |
+ "'" (~["'","\\","\n","\r","\u2028","\u2029"] | "\\" ~["\n","\r","\u2028","\u2029"])* "'"
+ >
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=922023&r1=922022&r2=922023&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java Thu Mar 11 21:13:34 2010
@@ -332,4 +332,45 @@ public class IssuesTest extends JexlTest
assertEquals("bye...", script.execute(ctxt));
}
+ public void test97() throws Exception {
+ JexlContext ctxt = new MapContext();
+ for(char v = 'a'; v <= 'z'; ++v) {
+ ctxt.set(Character.toString(v), 10);
+ }
+ String input =
+ "(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";
+
+ JexlEngine jexl = new JexlEngine();
+ Expression script;
+ // Make sure everything is loaded...
+ long start = System.nanoTime();
+ script = jexl.createExpression(input);
+ Object value = script.evaluate(ctxt);
+ assertEquals(Integer.valueOf(11), value);
+ long end = System.nanoTime();
+ System.out.printf("Parse took %.3f seconds\n", (end-start)/1e+9);
+ }
+
+ public static class fn98 {
+ public String replace(String str, String target, String replacement) {
+ return str.replace(target, replacement);
+ }
+ }
+
+ public void test98() throws Exception {
+ String[] exprs = {
+ "fn:replace('DOMAIN\\somename', '\\\\', '\\\\\\\\')",
+ "fn:replace(\"DOMAIN\\somename\", \"\\\\\", \"\\\\\\\\\")",
+ "fn:replace('DOMAIN\\somename', '\\u005c', '\\u005c\\u005c')"
+ };
+ JexlEngine jexl = new JexlEngine();
+ Map<String,Object> funcs = new HashMap<String,Object>();
+ funcs.put("fn", new fn98());
+ jexl.setFunctions(funcs);
+ for(String expr : exprs) {
+ Object value = jexl.createExpression(expr).evaluate(null);
+ assertEquals(expr, "DOMAIN\\\\somename", value);
+ }
+ }
+
}