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 2019/10/29 15:57:54 UTC

[commons-jexl] 01/07: JEXL-315: added handling of delimiters at end of lines Task #JEXL-315 - JxltEngine literal string strings ending in \ $ or # throw JxltEngine$Exception

This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit c46fb0d5084c17b648088b36cfdf648f67328d5c
Author: henrib <he...@apache.org>
AuthorDate: Sun Oct 27 13:37:02 2019 +0100

    JEXL-315: added handling of delimiters at end of lines
    Task #JEXL-315 - JxltEngine literal string strings ending in \ $ or # throw JxltEngine$Exception
---
 .../commons/jexl3/internal/TemplateEngine.java       | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
index 4609a3f..449848d 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
@@ -289,7 +289,7 @@ public final class TemplateEngine extends JxltEngine {
          * @return the expression value
          * @throws JexlException
          */
-        protected final TemplateExpression prepare(Scope.Frame frame, JexlContext context) {
+        protected final TemplateExpression prepare(Frame frame, JexlContext context) {
             try {
                 Interpreter interpreter = new TemplateInterpreter(jexl, context, frame, null, null);
                 return prepare(interpreter);
@@ -325,7 +325,7 @@ public final class TemplateEngine extends JxltEngine {
          * @return the expression value
          * @throws JexlException
          */
-        protected final Object evaluate(Scope.Frame frame, JexlContext context) {
+        protected final Object evaluate(Frame frame, JexlContext context) {
             try {
                 Interpreter interpreter = new TemplateInterpreter(jexl, context, frame, null, null);
                 return evaluate(interpreter);
@@ -883,7 +883,21 @@ public final class TemplateEngine extends JxltEngine {
         }
         // we should be in that state
         if (state != ParseState.CONST) {
-            throw new Exception(info.at(lineno, 0), "malformed expression: " + expr, null);
+            // otherwise, we ended a line with a \, $ or #
+            switch (state) {
+                case ESCAPE:
+                    strb.append('\\');
+                    strb.append('\\');
+                    break;
+                case DEFERRED0:
+                    strb.append(deferredChar);
+                    break;
+                case IMMEDIATE0:
+                    strb.append(immediateChar);
+                    break;
+                default:
+                    throw new Exception(info.at(lineno, 0), "malformed expression: " + expr, null);
+            }
         }
         // if any chars were buffered, add them as a constant
         if (strb.length() > 0) {