henrib commented on code in PR #427:
URL: https://github.com/apache/commons-jexl/pull/427#discussion_r4552335332


##########
src/changes/changes.xml:
##########
@@ -29,6 +29,7 @@
     <body>
         <release version="3.7.2" date="YYYY-MM-DD" description="This is a 
feature and maintenance release. Java 8 or later is required.">
             <!-- FIX -->
+            <action dev="henrib" due-to="Claude" type="fix" 
issue="JEXL-477">Interpolation strings are parsed with the engine features 
instead of those of their script.</action>

Review Comment:
   Kept as is: in this file, fix entries state the problem as the JIRA title 
does (see the JEXL-475 and JEXL-466 entries next to it).



##########
src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java:
##########
@@ -912,24 +916,38 @@ public JxltEngine.Expression createExpression(final 
JexlInfo jexlInfo, final Str
     }
 
     public JxltEngine.Expression createExpression(final JexlInfo jexlInfo, 
final String expression, final Scope scope) {
+        return createExpression(jexlInfo, expression, scope, null);
+    }
+
+    /**
+     * Creates an expression that is embedded in a script, an interpolation.
+     *
+     * @param jexlInfo   The source info
+     * @param expression The expression source
+     * @param scope      The scope
+     * @param ftrs       The features of the script the expression is embedded 
in, null for those of the engine
+     * @return The expression
+     */
+    public JxltEngine.Expression createExpression(final JexlInfo jexlInfo, 
final String expression, final Scope scope,
+                                                  final JexlFeatures ftrs) {
         final JexlInfo info = jexlInfo == null ?  jexl.createInfo() : jexlInfo;
         Exception xuel = null;
         TemplateExpression stmt = null;
-        final JexlFeatures features = noscript ? jexl.expressionFeatures : 
jexl.scriptFeatures;
+        final JexlFeatures features = features(ftrs);
         // do not cache interpolation expression, they are stored in AST node

Review Comment:
   Fixed in 0fe4d796. The comment predates this change and was stale; it now 
says that expressions shorter than the cache threshold are cached, keyed by 
features, symbols and source.



##########
src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java:
##########
@@ -987,7 +1005,35 @@ char getImmediateChar() {
      * @return The unified expression instance
      * @throws JexlException if an error occurs during parsing
      */
-    TemplateExpression parseExpression(final JexlInfo info, final String expr, 
final Scope scope) {  // CSOFF: MethodLength
+    TemplateExpression parseExpression(final JexlInfo info, final String expr, 
final Scope scope) {
+        return parseExpression(info, expr, scope, features(null));
+    }
+
+    /**
+     * Gets the features used to parse the JEXL expressions of a unified 
expression.
+     *
+     * @param ftrs The features of the script the unified expression is 
embedded in, null for those of the engine
+     * @return The features
+     */
+    private JexlFeatures features(final JexlFeatures ftrs) {
+        if (ftrs == null) {
+            return noscript ? jexl.expressionFeatures : jexl.scriptFeatures;
+        }
+        return noscript && ftrs.supportsScript() ? new 
JexlFeatures(ftrs).script(false) : ftrs;
+    }

Review Comment:
   Kept as is: it is a private helper with a single purpose, documented by its 
javadoc; the local variable holds its result.



##########
src/main/java/org/apache/commons/jexl3/parser/JexlParser.java:
##########
@@ -1170,16 +1170,18 @@ public ASTJexlScript jxltParse(final JexlInfo info, 
final JexlFeatures features,
      * @param info The JexlInfo
      * @param src The source to parse
      * @param scope The scope
+     * @param features The features of the script the expression is embedded in
      * @return The expression
      */
-    static JxltEngine.Expression parseInterpolation(final JexlInfo info, final 
String src, final Scope scope) {
+    static JxltEngine.Expression parseInterpolation(final JexlInfo info, final 
String src, final Scope scope,
+                                                    final JexlFeatures 
features) {
         final JexlEngine jexl = JexlEngine.getThreadEngine();
         if (jexl != null) {
             // interpolation uses default $ and # as expression markers;
             // the cache size is negative to reuse the engine cache
             final JxltEngine jxlt = jexl.createJxltEngine(true, -1, '$', '#');
             if (jxlt instanceof TemplateEngine) {
-                return ((TemplateEngine) jxlt).createExpression(info, src, 
scope);
+                return ((TemplateEngine) jxlt).createExpression(info, src, 
scope, features);
             }
         }
         throw new IllegalStateException("engine is not a accessible");

Review Comment:
   Fixed in 0fe4d796 (the typo predates this change): the message is now 
"engine is not accessible".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to